Beginner10 min readUpdated Jan 2025

Docker Volumes Explained Visually (Beginner-Friendly Docker Storage Guide)

A simple explanation of Docker Volumes. Learn where Docker stores data, why container data disappears, how volumes work, the types of volumes, and real examples for beginners.


1. Why Do We Even Need Docker Volumes? (Explained Simply)

When you run a container, everything inside it is temporary.

Example:

docker run mysql

You add some data to MySQL… You stop the container… You start again… Everything is gone.

Why? Because containers are not meant to store permanent data. They are like temporary rooms β€” when removed, everything inside gets wiped.

So we need a way to store data outside the container but still allow the container to use it.

And that solution is:

πŸ‘‰ Docker Volumes = Safe storage for your container’s data


This image is generated by gemini a google product

2. Visual Concept of a Volume (Your Style)

Imagine:

Container = Temporary apartment
Volume = Locker outside the apartment

Even if the container dies β†’ The locker still holds your data.

Visual Diagram:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Container (MySQL)    β”‚
β”‚    /var/lib/mysql      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ Volume link
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Docker Volume Storage β”‚
β”‚   (Permanent Data)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

3. Types of Volumes (Explained Visually)

There are 3 ways Docker stores data:


1 Anonymous Volumes

Docker creates a random volume automatically.

docker run -v /data app

Visual:

Container β†’ volume123 (unknown name, auto-generated)

2 Named Volumes

You give the volume a name.

docker run -v mydata:/data app

Visual:

Container β†’ mydata β†’ stored forever

3 Bind Mounts

You connect a real folder from your computer.

docker run -v /home/user/project:/app app

Visual:

Host Folder ↔ Container Folder

Best for development.


4. Real Example β€” Storing MySQL Data With a Volume

Let’s run MySQL the wrong way first:

docker run -e MYSQL_ROOT_PASSWORD=pass -d mysql

If container stops β†’ ALL data gone.

Now the correct way:

docker run -e MYSQL_ROOT_PASSWORD=pass \
  -v mysqldata:/var/lib/mysql \
  -d mysql

Visual Breakdown:

mysqldata (volume)  
    ↓  
/var/lib/mysql inside container

β†’ MySQL saves everything in the volume
β†’ Even if container dies, data stays

5. Where Are Volumes Stored?

On Linux:

/var/lib/docker/volumes/<your-volume-name>/

Docker manages it. You don’t manually touch these folders.


6. Create Your Own Volume (Beginner Exercise)

Step 1: Create a volume

docker volume create demo

Step 2: Run a container and use it

docker run -v demo:/data -d busybox sh -c "echo hello > /data/hello.txt && sleep 1000"

Step 3: Inspect volume

docker volume inspect demo

You will see:

  • storage path
  • mount point
  • driver

This is how you understand volumes practically.


7. Visual Summary (For Instant Recall)

Containers = temporary  
Volumes = permanent  
Use volumes for: databases, uploads, logs, anything important  
Types = anonymous, named, bind mount  
Volume lives even if container dies  

8. When Should You Use a Volume? (Simple Rules)

βœ” Use Volumes When:

  • Using databases (MySQL, MongoDB, Postgres)
  • Storing logs
  • Storing user uploads
  • Running containers in production
  • Your container must survive restarts

βœ” Use Bind Mounts When:

  • You are developing code locally
  • You want live code edits reflected inside container

Do NOT store data inside container filesystem if:

  • You care about persistence
  • You need real production setup
  • You want portability

**9.FAQ **

Q1. Why does Docker delete my data when container stops?

Because container filesystem is temporary. Only volumes are permanent.

Q2. Are volumes faster than bind mounts?

Yes. Volumes are optimized by Docker for performance.

Q3. Can two containers share one volume?

Yes. A volume can be mounted into multiple containers at once.

Q4. Does deleting a container delete the volume?

No. Volumes stay until you delete them manually.

Q5. How do I delete a volume?

docker volume rm myvolume

Final Words

Docker volumes solve one big headache:

β€œBro, my data is gone… again.”

With volumes, your data becomes safe, permanent, and separate from the container.

Containers can come and go β€” but your volume stays loyal like a storage vault outside the container’s house.

This is one of the biggest mindset shifts in Docker.

Mastered this concept?

Take the next step in your journey to becoming a senior developer.