← Docker learning pathDocker · Module 5 of 10
Volumes and data
Data inside a container is lost when it is removed; volumes keep it safe.
📖 Key ideas
- A container's writable layer disappears when the container is removed.
- Volumes store data outside the container and survive restarts and removal.
- -v dbdata:/var/lib/mysql mounts a named volume.
- Bind mounts map a host folder: -v ./site:/usr/share/nginx/html.
- Back up volumes; they hold your real data.
💡 Real-life example: A container is a hotel room; a volume is your locker that keeps your things when you check out.
VolumeDocker-managed storage that survives containers
Bind mountA host folder mapped into a container
Writable layerTemporary changes inside a container
-vFlag that attaches storage