Storage — Cheat Sheet
Docker · 1 topics. Download the PDF or the Instagram carousel and share it.
Cheat Sheet · AiCanCode.org
Storage
Docker1 topicsQuick revision reference
1
Docker Volumes & Persistence
Container filesystems are ephemeral — data is lost when a container is removed. Docker volumes and bind mounts persist data outside the container lifecycle.
- ✓Container writable layers are ephemeral — data is lost when the container is removed.
- ✓Named volumes are Docker-managed and persist across container restarts and deletions.
- ✓Bind mounts expose host directories into the container — ideal for development.
- ✓tmpfs mounts store data in memory only — useful for secrets and temp files.
- ✓Back up volumes by running a temporary Alpine container that tars the mounted volume.
- ✓Database containers (Postgres, MySQL, Redis) always need a named volume in production.
bash — named volume vs bind mount
# ── Named Volume ─────────────────────────────────────── # Create a volume docker volume create postgres-data # Use it (postgres writes to /var/lib/postgresql/data → saved in volume) docker run -d \ --name postgres \ -v postgres-data:/var/lib/postgresql/data \ # named volume mount -e POSTGRES_PASSWORD=secret \ postgres:16 # Data persists across container removal/recreation: docker rm -f postgres docker run -d --name postgres -v postgres-data:/var/lib/postgresql/data postgres:16 # ↑ same data — the volume still has it # ── Bind Mount ───────────────────────────────────────── # Mount current directory into container (hot-reload for dev) docker run -d \ --name dev-server \ -v $(pwd)/src:/app/src \ # host path:container path -p 3000:3000 \ my-app:dev # Edit src/ on host → changes immediately visible inside container
Learn this free with Aria, your AI tutor → AiCanCode.org/learn/docker