# Day 19 - Docker Volume

Hello Readers👩‍💻👩‍💻

it's my day19 of #90daysDevopsChallenge

Today's Topic

✅ Docker Volume

✅ Task for Day 19

### Docker Volume

Docker Volumes are **file systems mounted on Docker containers to preserve data generated by the running container**. Volumes have several advantages over bind mounts, such as automatically creating a directory for the volume on the host under the /var/lib/docker/volume/ path, allowing for data persistence and sharing among multiple containers.

### Command to create the new Volume

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683718347291/a59baa65-f19f-42b6-8eb9-19b040a0e174.png align="center")

### Tasks-

Create a multi-container docker-compose file that will bring *UP* and bring *DOWN* containers in a single shot ( Example - Create application and database container )

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683718827679/9661cecf-aa81-4456-8f2d-a0d8b3689661.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683718756117/1c0b8c05-87d8-41f8-ac71-ff437d8d22e7.png align="center")

* Use the `docker-compose up` command with the `-d` flag to start a multi-container application in detached mode.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683721305175/88281192-4c49-4885-8e80-72a56c922cb3.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 the deployment file for *auto-scaling*.
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683721885298/3da31280-2867-4570-a4fd-f0670e3980b6.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/v1683722665310/3fe22cd1-b2c8-45e2-9c2e-956b1e3b5abe.png align="center")
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683722785991/6e5c3f7d-0656-4f13-a1c4-7d45a8e1d497.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/v1683722870852/5af60fd6-c5ee-4248-a814-eea49b8a5b8c.png align="center")

## Task-2

* Learn how to use Docker Volumes and Named Volumes to share files and directories between multiple containers.
    
* To create a docker volume
    
    * Create two or more containers that read and write data to the same volume using the `docker run --mount` command.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683723287915/b7d4d385-4bfc-41ec-b416-e6bf29a42f8f.png align="center")
        
        • To mount the container
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683723644937/fe7833f8-361b-40d0-92c4-cbfc2e78b6f1.png align="center")
        
        • Verify that the data is the same in all containers by using the docker exec command to run commands inside each container.
        

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683724334554/19d07e38-b405-4fe1-9864-5a35603c474b.png align="center")

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

List the volume

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683724538021/94bf5310-7abf-4b22-b604-22fc0c2ea30a.png align="center")

To Remove the volume

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683724692069/12d7d4fe-33c6-49ff-b4a7-d0bace30c119.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1683724792701/ee17cec1-0ad3-4abd-9f0e-628081aaa4a7.png align="center")

I appreciate you taking the time to read my blog, and I hope you found it informative. If you found the content useful, please consider giving it a like, sharing it with others, and following me for more similar posts in the future. Thank you for your support!

LinkedIn Profile-[**https://**](https://www.linkedin.com/in/shreyakhangan/)[**www.linkedin.com/in/shreyakhangan/**](http://www.linkedin.com/in/shreyakhangan/)
