0 / 11 lessons — 0%
Lesson 08 / 11
Volumes & data persistence
Containers are meant to be disposable — but your data usually isn't. Delete a container and its writable layer disappears with it, so anything worth keeping goes in a volume or a bind mount instead.
| Type | Managed by | Typical use |
|---|---|---|
| Volume | Docker (/var/lib/docker/volumes) | Databases, app state — portable, backupable |
| Bind mount | You — an exact host path | Local dev: live-mount your source code |
| tmpfs | Memory only, never written to disk | Secrets, ephemeral scratch space |
A volume is Docker's own storage; a bind mount points straight at a folder you chose on the host.
# named volume — Docker manages where it actually lives docker volume create db-data docker run -d -v db-data:/var/lib/postgresql/data postgres:16 # bind mount — maps an exact host folder in, great for local dev docker run -v "$(pwd)":/app -w /app node:20 npm run dev docker volume ls docker volume inspect db-data
Try it yourselfStart a Postgres container with a named volume, write some data into it, then
docker rm -f the container and start a fresh one pointed at the same volume. The data's still there — that's the whole point.