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.

TypeManaged byTypical use
VolumeDocker (/var/lib/docker/volumes)Databases, app state — portable, backupable
Bind mountYou — an exact host pathLocal dev: live-mount your source code
tmpfsMemory only, never written to diskSecrets, ephemeral scratch space
container /var/lib/postgresql/data volume docker-managed host path bind mount
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.