Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Volumes

Direct answer

Volumes keep container data outside the container's writable layer: named volumes (managed by Docker) and bind mounts (host paths).

When to use this

Use it to persist data, or when data disappears or the container cannot write to a mount.

First 30 seconds

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.

Operational verification

volume or host path → mounted into the container → app writes there → survives container removal

Evidence · next step

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
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it to persist data, or when data disappears or the container cannot write to a mount.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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 references

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.

observation · 1
Key points

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.

Key checks
  • docker ps -a / podman ps -a — containers and state
  • docker logs <c> — container output
  • docker inspect <c> — configuration, mounts, network
  • docker 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 prune cleans them up.
  • --mount is preferred over -v because it's explicit, and it's required for some options.

Choosing a mount type

NeedMount
Database or application dataNamed volume
Configuration files from the hostBind mount, read-only
Source code during developmentBind mount
Sensitive temporary data, scratch spacetmpfs
Data shared between containersA 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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:

TypeExampleNotes
Named volume-v pgdata:/var/lib/postgresql/dataManaged under /var/lib/docker/volumes, portable between containers
Bind mount-v /srv/app/config:/etc/app:roHost path; ownership/SELinux matters (:Z/:z)
tmpfs--tmpfs /runRAM 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

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%
Technical changelog & impact

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.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

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.

Aliases that resolve here
docker volumescontainer persistent storagebind mount container
Embedded reference data

Quick lookup tables

Volumes operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for Volumes.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateContainer 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 verificationPin 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 chainvolume/bind source → runtime mount spec → namespace mount → ownership/LSM → application path → durable I/OTrace requested/configured state through effective state to the observed workload result.
Failure boundaryA 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 evidenceCorrelated Linux container/virtualization evidence can establish this proof path: volume/bind source → runtime mount spec → namespace mount → ownership/LSM → application path → durable I/OUse this observation only for the specific claim it actually supports.
Evidence limitIt 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 checkContinue 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 boundaryVolumes
Topic pathContainers → Volumes
Runtime stateContainer 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 chainvolume/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 boundaryA 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 ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?