Docker Volumes & Bind Mounts

Hi there! I'm Dinesh, a passionate Cloud and DevOps enthusiast. I love to dive into the latest new technologies and sharing my journey through blog.
Search for a command to run...

Hi there! I'm Dinesh, a passionate Cloud and DevOps enthusiast. I love to dive into the latest new technologies and sharing my journey through blog.
No comments yet. Be the first to comment.
1. Difference between Docker and Kubernetes Docker → Builds and runs containers.Kubernetes → Orchestrates containers across multiple nodes. Key points: Docker = container runtime. Kubernetes = container orchestration tool. Kubernetes provides auto...
In this session, we learn how to monitor a Kubernetes cluster using Prometheus and Grafana.This is not just theory — there is a GitHub repository containing all installation commands and demo steps.The repo will also be enhanced later with advanced K...
1. What is a ConfigMap in Kubernetes? A ConfigMap is used to store non-sensitive configuration data that your application needs — such as: Database port Connection type Any general configuration values In normal applications (non-Kubernetes), de...
Kubernetes normally supports built-in resources like: Deployment Service Pod ConfigMap Secret Ingress These are called native resources. Sometimes companies (Istio, ArgoCD, Prometheus Operator, Kyverno, etc.) want to add new features that Kub...
1. Why Kubernetes Services Are Needed When a Pod is created in Kubernetes, it receives a dynamic IP address.If the Pod dies and restarts, its IP changes.So other Pods (like checkout → payments) cannot rely on Pod IP because it changes, creating issue...
In Docker, a volume is a mechanism for persisting data generated and used by containers. Volumes are stored on the host filesystem outside the container's file system, making them an ideal solution for managing persistent data in a containerized environment.
Step 1 : Create a Volume
docker volume create my-vol

Step 2 : Verify the Volume Creation
docker volume ls

Inspect the created volume
docker inspect my-vol

Step 3 : Access the Volume
Navigate to the volume's mount point on the host system:
cd /var/lib/docker/volumes/my-vol/_data

Step 4 : Run Containers Using the Volume
Launch a container with the volume mounted to port 5050:
docker run -itd --mount source=my-vol,destination=/usr/local/apache2/htdocs -p "5050:80" httpd

Launch another container using the same volume but on port 6060:
docker run -itd --mount source=my-vol,destination=/usr/local/apache2/htdocs -p "6060:80" httpd

Step 5 : Verify Content Synchronization
Now i have launched 2 containers with different port

Read the index.html file in inside volume

Access the container on port 5050 and 6060. You'll see the same content because both containers share the same volume.
5050 port

6060 port

Update the index.html file in the volume.


The changes will reflect immediately in both containers at ports 5050 and 6060.
5050 port

6060 port

Bind mounts allow you to link a directory or file from the host system to a container. Changes made to the bind-mounted file or directory are immediately reflected on both the host and the container.
Step 1 : Prepare the Host Directory
Create a directory on your host that you want to mount into the container:

Step 2 : Run a Container with a Bind Mount
Launch a Docker container with the bind mount specified:
docker run -itd -p "6060:80" -v "/root/docker-sync:/usr/local/apache2/htdocs" httpd

Step 3 : Verify the Container
Check running containers:
docker ps

Access the container’s terminal:
docker exec -it 13ad964d0800 /bin/bash

Navigate to the /usr/local/apache2/htdocs directory inside the container:
Initially, the directory may be empty.

Exit the container

Now, Check the container port number, it is showing default content

Create an index.html file in the /root/docker-sync directory on your host machine.


Step 4 : Check Content Synchronization
Refresh the container’s content by accessing it via the public IP and port 6060. The index.html file content should automatically update inside the container reflecting changes made on the host.

Docker Volumes: Docker volumes are ideal for persisting and sharing data across containers, ensuring data remains consistent and managed even when containers are recreated.
Docker Bind Mounts: Bind mounts enable real-time synchronization between host files and containers, making them perfect for development scenarios where immediate file updates are needed.