Day 18 - 90daysofdevops: Docker for DevOps Engineers Part 2 - Docker Compose

Day 18 - 90daysofdevops: Docker for DevOps Engineers Part 2 - Docker Compose

What id Docker Compose?

Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to manage multiple containers as a single service, simplifying the process of setting up and running complex applications. Docker Compose uses a YAML file to define the services that make up your application, and it provides a set of commands for starting, stopping, and managing those services.

Docker Compose benefits:

  • Define your application's services in a YAML file.
  • Start, stop, and manage your application's services with a single command.
  • Share your application's configuration with others easily.
  • Use Docker Compose in all environments, including production, staging, development, testing, and CI workflows.

The most common Docker Compose commands:

  • docker-compose up: This command starts all of the services defined in your Compose file.
  • docker-compose down: This command stops and removes all of the containers and networks defined in your Compose file.
  • docker-compose PS: This command lists all of the running containers for your Compose project.
  • docker-compose logs: This command streams the logs for all of the running containers for your Compose project.

Article content

What is YAML?

YAML (YAML Ain't Markup Language) is a human-readable data serialization language commonly used for configuration files. It is often used in conjunction with programming languages, such as Python, Ruby, and JavaScript, to define application settings and data structures. YAML is designed to be easy to read and write, and it uses indentation to determine the structure of data.

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

YAML: This YAML file defines a configuration object with four properties: name, email, address, and zip. The address property is a nested object that defines the street address, city, state, and zip code.

name: John Doe
email: johndoe@example.com
address:
  street: 123 Main Street
  city: Anytown
  state: CA
  zip: 98765        

Task-1

Learn how to use the docker-compose.yml file, to set up the environment, configure the services and links between different containers, and also to use environment variables in the docker-compose.yml file.

Article content
docker-compose.yml file
Article content
docker-compose up -d
Article content
docker images
Article content
docker ps -a
Article content
http://ipaddress

I'm able to enter into MYSQL database container:

Article content
docker exec -it containerID /bin/bash
Article content

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 the user permission to docker).

Pulling the image httpd Apache server

Article content
docker pull image-Name
Article content
docker images

  • Run as a Non-Root User:

usermod -aG docker your_username
# Reboot your machine        
Article content
docker images

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

Article content
docker inspect <container-id>

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

Article content
docker logs <container-id>

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

Article content
docker stop <container-id>
Article content
docker start <container-id>

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

Article content
docker rm <container-id> -f

🐳🐳Happy Learning!! #90daysofdevops#devops#docker#dockerfile#dockercompose

To view or add a comment, sign in

More articles by Prakash B Bohara

Others also viewed

Explore content categories