Use it to persist data, or when data disappears or the container cannot write to a mount.
Volumes
Volumes keep container data outside the container's writable layer: named volumes (managed by Docker) and bind mounts (host paths).
1. docker inspect <c> --format '{{json .Mounts}}' — what is mounted where?
2. Permission denied → container UID vs host owner (ls -ln).
3. SELinux → add :Z to the bind mount.
4. docker volume ls / inspect — location.
5. Back up and test restore.
volume or host path → mounted into the container → app writes there → survives container removal
For Containers → Volumes, continue with the first unproven Topic check: Pin exact host, runtime/hypervisor, object identity, source revision/image/definition and failing workload. If that boundary is healthy, advance to the adjacent check: Read back effective runtime state including process, namespace/resource or virtual-hardware boundaries. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.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 Operational evidence path Verify boundary
volume/bind source → runtime mount spec → namespace mount → ownership/LSM → application path → durable I/O
Healthy evidence: the intended source is mounted at the intended target with correct identity/security semantics and fresh data survives the expected lifecycle
Step 2 Verification and output interpretation Verify boundary
Verification chain. volume/bind source → runtime mount spec → namespace mount → ownership/LSM → application path → durable I/O
Step 3 Commands Verify boundary
docker volume ls
docker volume inspect data
docker run -v data:/var/lib/app app:1.0
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: wrong anonymous volume, bind path, UID/GID, SELinux label or stale data makes the container appear healthy while persistence is wrong
A listed volume or mount entry does not show the application writes the intended durable backend.
Step 5 Common mistakes Narrow the fault
- Data written inside the container layer.
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.
Data in the container layer is lost on removal. Bind mounts need host permissions matching the container user and, on SELinux hosts, :z/:Z labels. Back up volumes.
docker ps -a / podman ps -a— containers and statedocker logs <c>— container outputdocker inspect <c>— configuration, mounts, networkdocker info— engine, storage driver, cgroup version
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
A listed volume or mount entry does not show the application writes the intended durable backend.
In depth
Container storage: volumes, bind mounts and tmpfs
Anything written into a container's own file system is lost when the container is removed. Persistent data belongs in a mount. Docker's volume documentation describes the options:
- Volumes are managed entirely by Docker, and stored under
/var/lib/docker/volumes/<name>/_data. - Bind mounts map a host path into the container, and depend on the host's directory layout.
- tmpfs mounts keep data in memory only.
It also explains the life cycle:
- Named volumes outlive their containers.
- Anonymous volumes also persist, unless the container ran with
--rm. - Unused volumes aren't removed automatically, and
docker volume prunecleans them up. --mountis preferred over-vbecause it's explicit, and it's required for some options.
Choosing a mount type
| Need | Mount |
|---|---|
| Database or application data | Named volume |
| Configuration files from the host | Bind mount, read-only |
| Source code during development | Bind mount |
| Sensitive temporary data, scratch space | tmpfs |
| Data shared between containers | A named volume mounted in each (read-only where possible) |
Syntax
-v form | --mount form |
|---|---|
-v pgdata:/var/lib/postgresql/data | --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data |
-v /etc/app/config.yml:/app/config.yml:ro | --mount type=bind,src=/etc/app/config.yml,dst=/app/config.yml,readonly |
--tmpfs /run/app:size=64m | --mount type=tmpfs,dst=/run/app,tmpfs-size=67108864 |
Backing up a volume (documentation)
Docker's suggested method runs a temporary container that mounts the volume (--volumes-from, or the volume itself) plus a host directory, then archives the data with tar. For databases, a database-level dump is usually better than copying live files.
host$ docker volume create pgdata
host$ docker run -d --name db --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data -e POSTGRES_PASSWORD_FILE=/run/secrets/pg postgres:16
host$ docker volume inspect pgdata -f '{{.Mountpoint}}'
/var/lib/docker/volumes/pgdata/_data
host$ docker run --rm --mount type=volume,src=pgdata,dst=/data,readonly -v /srv/backup:/backup alpine tar czf /backup/pgdata-$(date +%F).tgz -C /data .
host$ docker exec db pg_dumpall -U postgres | gzip > /srv/backup/pg-$(date +%F).sql.gz
host$ docker volume ls -f dangling=true
host$ docker run --rm -v /srv/app/config:/config:ro,Z alpine ls /config
SELinux and bind mounts
On SELinux hosts, a bind-mounted host directory must be relabelled for container access. The :Z suffix (private) or :z (shared) does that. Never use them on system directories such as /etc or /home: they relabel the whole tree.
Documented example, not captured output.
How it works at runtime
Volumes is part of Containers → Volumes. Container Volumes separate persistent data from container writable layers and require evidence of source, mount target, permissions, persistence and backup semantics.
Topic-specific state model. Container Volumes separate persistent data from container writable layers and require evidence of source, mount target, permissions, persistence and backup semantics.
Quick reference
Persistent data options:
| Type | Example | Notes |
|---|---|---|
| Named volume | -v pgdata:/var/lib/postgresql/data | Managed under /var/lib/docker/volumes, portable between containers |
| Bind mount | -v /srv/app/config:/etc/app:ro | Host path; ownership/SELinux matters (:Z/:z) |
| tmpfs | --tmpfs /run | RAM only |
docker volume ls; docker volume inspect pgdata
docker run --rm -v pgdata:/data -v $PWD:/backup alpine tar czf /backup/pgdata.tgz -C /data .
Back up volumes with application-consistent methods (database dumps), not just file copies of a running database.
Limits and how it fails
Primary failure point. A listed volume or mount entry does not show the application writes the intended durable backend.
Snapshot/image existence is not a verified backup.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Distribution/platform context. Volumes owns container persistence attachment; host filesystem/LVM/storage Topics own backing storage behavior.
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 Containers → Volumes. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.docker.com/engine/ · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Volumes operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for Volumes.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | Container Volumes separate persistent data from container writable layers and require proof of source, mount target, permissions, persistence and backup semantics. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin host + object identity + source image/definition → verify host/runtime capability → read back effective process/namespace/cgroup or virtual-hardware state → verify storage/network attachments → verify guest/container readiness → repeat original workload + regression check. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | volume/bind source → runtime mount spec → namespace mount → ownership/LSM → application path → durable I/O | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | A listed volume or mount entry does not prove the application writes the intended durable backend. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux container/virtualization evidence can establish this proof path: volume/bind source → runtime mount spec → namespace mount → ownership/LSM → application path → durable I/O | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove unobserved clients, names, identities, routes, sessions, backends or time periods. A listed volume or mount entry does not prove the application writes the intended durable backend. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven runtime boundary, capture adjacent host/object/resource/attachment evidence, make only the demonstrated persistent change, then repeat the original workload plus a regression check. | Continue to the next unresolved boundary while preserving the original test condition. |
Volumes · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | Volumes |
|---|---|
| Topic path | Containers → Volumes |
| Runtime state | Container Volumes separate persistent data from container writable layers and require proof of source, mount target, permissions, persistence and backup semantics. |
| Fast checks | - Pin exact host, runtime/hypervisor, object identity, source revision/image/definition and failing workload. - Read back effective runtime state including process, namespace/resource or virtual-hardware boundaries. - Trace storage and network attachments plus readiness from the real client or dependent workload path. - Apply the smallest persistent change, then repeat the original workload and an adjacent regression check. |
| Verification chain | volume/bind source → runtime mount spec → namespace mount → ownership/LSM → application path → durable I/O Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. |
| Failure boundary | A listed volume or mount entry does not prove the application writes the intended durable backend. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |