π¬ "Ever wondered why your appβs data disappears when you stop a container? In this episode, we uncover Docker Volumes β your key to persistent, reliable, and sharable data storage."
π§ Why Data Disappears in Docker
By default, Docker containers are ephemeral β which means:
- When the container stops, its filesystem is wiped.
- All your app logs, databases, and uploads? Gone. π«
This is great for clean environments⦠but not if you need data to stick around.
Enter: Docker Volumes.
π¦ What Is a Docker Volume?
A volume is a special folder outside the container, managed by Docker.
Think of it like:
- A USB drive you plug into your container
- When the container is deleted, the USB (volume) stays intact
You can re-attach it, share it across containers, and even back it up.
π§ Using Volumes in Real Projects
π§ͺ Example 1: MySQL Database Persistence
docker run -d \
--name mysql \
-e MYSQL_ROOT_PASSWORD=mysecret \
-v mysql-data:/var/lib/mysql \
mysql:latest
β
This creates a volume mysql-data
that stores the DB.
Even if you delete the container, the database stays.
π¨ Common Volume Commands
π List Volumes
docker volume ls
π Inspect a Volume
docker volume inspect mysql-data
β Remove a Volume
docker volume rm mysql-data
π§Ή Prune Unused Volumes
docker volume prune
π§± Volume Types (Simplified)
Type | Use Case |
---|---|
Named Volume | Long-term data (MySQL, logs, uploads) |
Bind Mount | Dev mode (sync local folders) |
π§ͺ Example 2: Dev Sync with Bind Mount
docker run -d \
-v $(pwd):/app \
-w /app \
node:18 \
npm start
β Any change you make locally reflects inside the container in real-time.
π οΈ Tips for Volume Mastery
- Use named volumes in production
- Use bind mounts for live development
- Clean up unused volumes regularly
π¦ Up Next: Docker Networking Demystified
In Episode 7, weβll explore:
- How containers talk to each other
- Networks, bridges, ports, and real examples (Node + DB)
π¬ Letβs Talk
Did you try volumes in your app yet? Still confused between named volumes and mounts?
Drop a question β Iβd love to help you debug or design the best volume setup.
β€οΈ If this episode helped keep your data safe, give it a like or share it with someone building with Docker.
π¬ Next: βDocker Networking β How Containers Talk Behind the Scenesβ
Top comments (0)