Demonstration on how Docker Volumes & Data Persistence
- Sharon Rajendra Manmothe

- 7 hours ago
- 1 min read
Step 1: Create a Docker Volume
docker volume create mydata
Explanation:This creates a persistent storage location managed by Docker.
Step 2: Run a Container Using the Volume
docker run -it --name testcontainer -v mydata:/data ubuntu
Explanation:
-v mydata:/data → Mount the volume inside container at /data
ubuntu → Runs Ubuntu container
/data → Any files created here will go into the volume
Step 3: Create a File Inside the Volume
Inside the container, type:
echo "Hello Docker Volume" > /data/info.txt
Check the file:
cat /data/info.txt
You will see:
Hello Docker Volume
Step 4: Exit the Container
Exit:
exit
Step 5: Remove the Container
docker rm testcontainer
Important:We removed the container, BUT the volume still exists.
Step 6: Run a New Container With Same Volume
docker run -it --name newcontainer -v mydata:/data ubuntu
Now check the data:
cat /data/info.txt
You will see:
Hello Docker Volume
Conclusion: Data Persistence
Container deleted
New container created
Data STILL EXIST
Because volumes are persistent and managed by Docker, not tied to any single container.
What You Learned
Feature | Meaning |
Volume | Persistent storage created by Docker |
Mounting | Attaching volume to container path |
Data Persistence | Data survives even after container deletion |

$50
Product Title
Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button

$50
Product Title
Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button.

$50
Product Title
Product Details goes here with the simple product description and more information can be seen by clicking the see more button. Product Details goes here with the simple product description and more information can be seen by clicking the see more button.



Comments