๐ฌ "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)