# Mastering Container Management with Docker Compose and Volumes: A Comprehensive Guide

Welcome to Day 19 of our #90daysofdevops challenge! Today, we will dive deeper into Docker and explore how to manage containers using Docker Compose and Volumes.Let's get started!

Task 1: Create a multi-container docker-compose file which will bring *UP* and bring *DOWN* containers in a single shot.

We will create below docker-compose.yml.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211236118/b5b66dfa-e746-40f7-855f-68f750b9d25c.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211333412/7f3d3e6c-08e1-48b7-bb49-a0fe1763789e.png align="center")

* Use the `docker-compose scale` command to increase or decrease the number of replicas for a specific service. You can also add [`replicas`](https://stackoverflow.com/questions/63408708/how-to-scale-from-within-docker-compose-file) in deployment file for *auto-scaling*.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211349302/3f764832-8c9e-4433-b20c-bb0db06ab53a.png align="center")

* Use the `docker-compose ps` command to view the status of all containers, and `docker-compose logs` to view the logs of a specific service.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211422070/cbd77440-9064-4166-a895-fbc8c4336a89.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211438025/ece92c04-ea1d-4373-b13e-4f193de84eca.png align="center")

* Use the `docker-compose down` command to stop and remove all containers, networks, and volumes associated with the application
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211467657/0717b6e2-5580-44fb-9754-43e87e3f4d3c.png align="center")

Task 2 : Create two or more containers that read and write data to the same volume using the `docker run --mount` command.

To demonstrate multiple containers reading and writing data to the same volume, let's launch two additional containers. Open your terminal and run the following commands:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211549354/46c4a9e1-b74c-4601-b88f-2917d010fbce.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211583253/05d09940-2498-4726-a666-51de68d35a68.png align="center")

Now let's write in volume.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211641543/0381fac9-4df7-4430-a4b6-7bc48df108e9.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211679074/6d9191b9-63d1-4477-9815-d31c5af1713d.png align="center")

Task 3 : Verify that the data is the same in all containers by using the docker exec command to run commands inside each container.

To read data using exec command :

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211764963/a0504e47-a6df-469c-9bb1-e7541ba40834.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211786168/d4bf49e0-7746-4f53-bd30-8fbdcf73a2b9.png align="center")

Task 4 : Use the docker volume ls command to list all volumes and docker volume rm command to remove the volume when you're done.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211841787/f20bf35a-4f8b-441c-baa0-6f5bf975ab04.png align="center")

To remove volume use following command:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1684211864643/bb6dee1f-64ff-4c61-aee5-7019d7539741.png align="center")

This was all for today. I hope my screenshots will help to clear your doubt. Looking forward to day20 challenge. If you have any suggestion/question please comment below.
