Use this when container data must persist.
Volumes
Volumes persist container data outside the container's writable layer, as named volumes or bind mounts. Back them up separately, since removing a container does not remove its data.
1. Volumes persist container data.
2. Named volumes for stateful apps.
3. Back them up.
4. Read-only mounts where possible.
5. Clean unused volumes carefully.
container → volume → host storage
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Verification path Verify boundary
The negative fixture should deliberately exercise risks such as mutable tags, orphaned containers/networks, volume data loss, environment drift, restart loops, port collisions and running container mistaken for healthy application, choosing the cases most relevant to Docker volume identity/driver/mountpoint, lifecycle independent of containers, backup/ownership and confirming data persists across container recreation.
Step 2 Common mistakes Narrow the fault
- Data in the container layer, lost on recreate.
- Bind mounts with wrong ownership.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Named volumes and bind mounts keep data outside containers.
- Removing a container does not remove its volume.
- Back up volumes separately.
docker volume ls— volumesdocker volume inspect <v>— mountpoint- Backup of named volumes — data protection
ReferenceWhy it matters1 section · depth on demand
What it is
Docker volumes persist data outside the container lifecycle.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
Volumes keep container data outside the container's writable layer, so it survives container recreation and upgrades. Databases, uploaded files and configuration state must live on volumes or bind mounts, or they disappear when the container is replaced.
| Type | Example | Use |
|---|---|---|
| Named volume | pgdata:/var/lib/postgresql/data | Managed by Docker; portable |
| Bind mount | ./config:/etc/app:ro | Host files, configuration |
| tmpfs | tmpfs: /tmp | In-memory scratch data |
docker volume ls
docker run --rm -v pgdata:/data -v "$PWD":/backup alpine tar czf /backup/pgdata.tgz -C /data .
For databases, prefer application-level backups (pg_dump) over copying volume files while the database is running.
Example
docker volume create pgdata
docker run -v pgdata:/var/lib/postgresql/data postgres:16
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Container Automation > Volumes. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.docker.com/ · confidence 94%Deep reference
Healthy vs suspicious evidence
Output interpretation
For Docker volume identity/driver/mountpoint, lifecycle independent of containers, backup/ownership and confirming data persists across container recreation, prefer typed fields and stable IDs over human presentation text.