Volumes & Data
A container's writable layer lives and dies with the container, so deleting the container takes everything written inside it. A volume mounts host-side storage onto a path in the container, putting the data outside the container's lifetime — which is why the database files survive even when you replace the container entirely.
01 Concept at a Glance
Interactive Step-by-StepStart a database without a volume and everything it accumulates goes into the container's writable layer.
A volume mounts host-side storage onto a path inside the container. Where the data lives moves outside the container.
02 Understand It Simply
For EveryoneUnpack your bags in a hotel room (the container) and housekeeping clears everything at checkout. A volume isn't the room safe — it's a storage unit at home wired into the room, so changing rooms doesn't touch your things.
Anything written to the writable layer vanishes the moment you rm the container.
Mount a volume and reads and writes on that path skip the container layer and go straight to host storage.
Docker-managed named volumes are portable and the usual production choice; bind mounts point at a host path you pick, which is handy for live-reloading source during development.
- –Persisting database data
- –keeping state across container upgrades
- –live-reloading source in development (bind mounts)
- –and sharing data between containers
03 Frequently Asked Questions
FAQWhat is Volumes & Data?+
A container's writable layer lives and dies with the container, so deleting the container takes everything written inside it. A volume mounts host-side storage onto a path in the container, putting the data outside the container's lifetime — which is why the database files survive even when you replace the container entirely.
Where is Volumes & Data used?+
Persisting database data, keeping state across container upgrades, live-reloading source in development (bind mounts), and sharing data between containers.
What's a simple analogy for Volumes & Data?+
Unpack your bags in a hotel room (the container) and housekeeping clears everything at checkout. A volume isn't the room safe — it's a storage unit at home wired into the room, so changing rooms doesn't touch your things.
