Day 18: Docker for DevOps Engineers

Docker Compose

  • Docker Compose is a tool that was developed to help define and share multi-container applications.

  • With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down.

Docker Compose Commands

Here's a list of common Docker Compose commands:

  1. docker-compose up: Create and start containers.

  2. docker-compose down: Stop and remove containers.

  3. docker-compose build: Build or rebuild services.

  4. docker-compose start: Start services.

  5. docker-compose stop: Stop services.

  6. docker-compose restart: Restart services.

  7. docker-compose logs: View service logs.

  8. docker-compose ps: List running containers.

  9. docker-compose exec: Execute a command in a running container.

What is YAML?

  • YAML is a data serialization language that is often used for writing configuration files. Depending on whom you ask, YAML stands for yet another markup language or YAML ain’t markup language (a recursive acronym), which emphasizes that YAML is for data, not documents.

  • YAML is a popular programming language because it is human-readable and easy to understand.

  • YAML files use a .yml or .yaml extension.

Components of the above file:

  1. Version: Version is used to specify the version of the Docker Compose file format being used. It is always the first line in the docker-compose.yml file.

  2. Services: Defines individual containers and their configurations.

  3. Images: Specifies the Docker images used for each service.

  4. Environment Variables: Sets environment variables for services.

  5. Ports: Maps container ports to the host system.

Checking the status of both servers:

We have successfully created the services using docker-compose.yaml

Task 2: Pull a pre-existing Docker image from a public repository (e.g. Docker Hub) and run it on your local machine.

Run the container as a non-root user (Hint- Use usermod command to give user permission to docker). Make sure you reboot instance after giving permission to user.

Inspect the container's running processes and exposed ports using the docker inspect command.

Use the docker logs command to view the container's log output.

Use the docker stop and docker start commands to stop and start the container.

Use the docker rm command to remove the container when you're done.

How to run Docker commands without sudo?

  • Make sure docker is installed and system is updated (This is already been completed as a part of previous tasks):

  • sudo usermod -a -G docker $USER

  • Reboot the machine.

I hope you like my blog..!!

Stay Connected with me for more interesting articles on DevOps, if you like my blog follow me on Hashnode and Linkedin (https://www.linkedin.com/in/som-shanker-pandey/

Did you find this article valuable?

Support Som Pandey's blog by becoming a sponsor. Any amount is appreciated!