Day 19 : Docker for DevOps Engineers

"Passionate about simplifying the complexities of DevOps, I bring 5 years of hands-on experience in supporting development and operations teams to achieve faster, more reliable software delivery. I thrive on optimizing CI/CD pipelines, automating workflows, and troubleshooting challenges across diverse cloud environments. My expertise spans across infrastructure management, continuous integration, and performance monitoring—ensuring stability and efficiency at every stage of the software lifecycle. Always eager to learn, collaborate, and innovate, I’m committed to driving impactful change in the DevOps space."
Exploring Docker Volumes, Networks, and Docker Compose Commands
So far, you’ve learned how to create a docker-compose.yml file and push it to a repository. Let’s dive deeper into Docker concepts like Docker Volumes, Docker Networks, and Docker Compose commands to effectively manage multi-container applications.
Docker Volumes
Docker Volumes allow containers to store and share data outside of their filesystem, making it easy to persist data. For example, if you’re running a database inside a container, you don’t want the data to be lost if the container is removed. By creating a volume, you can ensure the data remains available.
Key Points
Volume: Docker-managed storage space that persists beyond the container lifecycle.
Named Volume: A volume given a specific name, making it easier to reference and share across multiple containers.
Bind Mount: Directly mounts a host machine directory or file to a container, allowing more flexibility but can require handling permissions.
Example docker-compose.yml with Volumes
This example shows how to use volumes in a docker-compose.yml file for a simple web and database setup:

Commands to Manage the Setup
1. Installing Docker Compose on:

2.Start Multi-Container Application
To start the application in detached mode:
docker-compose up -d

This command:
Starts all services defined in the
docker-compose.ymlfile.Runs containers in the background so you can continue using the terminal.
3.View Container Status
To see the status of all containers in this Compose setup:
docker-compose ps
4. Stop and Clean Up
To stop and remove all containers, networks, and volumes associated with the application:
bashCopy codedocker-compose down

5 .Docker compose logs:

6:Docker container :



Task 2
Learn how to use Docker Volumes and Named Volumes to share files and directories between multiple containers.
Create two or more containers that read and write data to the same volume using the
docker run --mountcommand.Verify that the data is the same in all containers by using the
docker execcommand to run commands inside each container.Use the
docker volume lscommand to list all volumes and thedocker volume rmcommand to remove the volume when you're done.
To work with Docker Volumes and Named Volumes for sharing files between containers, here’s a step-by-step guide to help you understand and perform the tasks:
1. Create a Docker Volume
A Docker volume is a persistent storage mechanism that can be shared between containers.
To create a volume:

2. Run Containers Using the Volume
Now, you can run multiple containers and mount the volume in them. Use the --mount flag to attach the volume to the containers.
For example, run two containers (Container A and Container B), both sharing the volume

3. Write Data in One Container
You can write data in one container, and it will be shared with the other container:
Access the first container and write a file:

4. Read Data from Another Container
Now, access the second container and check if the file is present:

5. List Docker Volumes:

This article explores Docker Volumes, Networks, and Docker Compose commands for managing multi-container applications. It highlights how to use Docker Volumes to persist and share data outside the container filesystem, explains key concepts like Named Volumes and Bind Mounts, and provides example commands to manage Docker setups. Additionally, it offers a guide on using Docker Volumes to share files between containers, including steps to create volumes, run containers with shared volumes, and verify data consistency across containers.


