top of page

Demonstration on how Docker Volumes & Data Persistence


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.

Recommended Products For This Post
 
 
 

Recent Posts

See All
Demonstration of How to Do Port Mapping in Docker

STEP 1: Run NGINX on Port 8080 docker run -d --name mynginx -p 8080:80 nginx NGINX is running inside container on port 80 ✔ You are accessing it from host on 8080 Test: http://localhost:8080 STEP 2: T

 
 
 

Comments


© 2023 by newittrendzzz.com 

  • Facebook
  • Twitter
  • Instagram
bottom of page