Day 18 - 90daysofDevops

Docker Compose:

Docker Compose is a tool provided by Docker that allows you to define and manage multi-container Docker applications. It uses a YAML file to specify the services, networks, and volumes required for your application and provides a command-line interface to orchestrate the containers.

What is YAML?

YAML stands for Yet Another Markup Language.

It is a human-readable language used for writing configuration files.

It's recommended that configuration files be written in YAML rather than JSON, even though they can be used interchangeably in most cases because YAML has better readability and is more user-friendly.

YAML is used in DevOps tools like Ansible and Kubernetes.

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.

Install Docker compose on the system.

$ apt install docker-compose

Pull the source code from the GitHub repo and create the image.

$ docker build . -t django-notes-app

Create the docker-compose.yml file and include the containers you want to run with

its images.

  • 3.3 is the version of the docker-compose.

  • Services contain the number of containers or applications the user wants to run.

  • Ports refer to the particular application being exposed to an external URL.

  • Environment passes the credentials or data to be passed to the container.

Now the containers are up and you can monitor the application through the web URL.

After the task completion, you can use the below command to make the docker containers down.

$ sudo docker-compose down

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.

Use the below command to provide docker execute permission to non-admin user. You can check now all the docker commands can be executed without the prefix "sudo"

$ sudo usermod -a -G docker $USER

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

$ docker inspect <image_name>

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

$ docker logs <container_id>

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

$ docker stop <container_id>

$ docker start <container_id>

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

$ docker rm <container_id>

Thanks for reading