C.W.K.
Stream
Lesson 02 of 05 · published

Three Storage Types — Volumes, Bind Mounts, tmpfs

~14 min · data, concepts

Level 0Container Curious
0 XP0/36 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Docker offers three persistence mechanisms

TypeStored atBest for
Named volumeDocker-managed area on host (/var/lib/docker/volumes/)Production data, databases, anything Docker should own
Bind mountAny path on the host filesystemDevelopment (mount your source, hot-reload), config files, shared dirs
tmpfs mountRAM (host memory)Secrets, fast scratch space, anything that should never touch disk

Quick syntax

Code

Three flags, three mechanisms·bash
# Named volume (Docker-managed)
docker run -d -v pgdata:/var/lib/postgresql/data postgres:16

# Bind mount (host path → container path)
docker run -it --rm -v $(pwd)/src:/app/src python:3.12 sh

# tmpfs (RAM-only)
docker run -d --tmpfs /app/cache:size=100m,mode=1777 myapp
The newer --mount syntax (more explicit)·bash
docker run -d \
  --mount type=volume,source=pgdata,target=/var/lib/postgresql/data \
  --mount type=bind,source=$(pwd)/config.yaml,target=/app/config.yaml,readonly \
  --mount type=tmpfs,target=/app/cache,tmpfs-size=104857600 \
  myapp

# More verbose, but every option is explicit. Compose files use this shape.

External links

Exercise

Run the same Postgres container twice — once with a bind mount on ~/pgdata, once with a named volume pgdata. Insert data into each. Now move both pointer paths around with docker volume inspect (for the named volume) and ls on the bind path. Which is easier to back up? Which is easier to migrate to another host?

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.