Oh My Algorithm
Concept GuidePersistence · Mounts

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-Step
No Volume · Writing to the Container Layer
Container · postgres
postgres process
Writable layer/var/lib/postgresql/data
Image layers (read-only)
Host filesystem — nothing is stored here

Start a database without a volume and everything it accumulates goes into the container's writable layer.

Logic Node1 / 4
Volume Mount · Keeping Data Outside
Container · postgres
postgres process
Mount point/var/lib/postgresql/data
Image layers (read-only)
-v pgdata:/var/lib/postgresql/data · bypasses the writable layer
WALrowidxrow
named volume · pgdataDocker-managed · portable
bind mount · ./srchost path, chosen by you
Host filesystem — outlives any container

A volume mounts host-side storage onto a path inside the container. Where the data lives moves outside the container.

Logic Node1 / 6

02 Understand It Simply

For Everyone
🔑Analogy

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.

💡In Plain Words

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.

📍Where It's Used
  • Persisting database data
  • keeping state across container upgrades
  • live-reloading source in development (bind mounts)
  • and sharing data between containers

03 Frequently Asked Questions

FAQ
What 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.

Guide Progress0%