Pcornel
Browse topics
Options
Recent
Favorites
Containers · Technical reference

Volumes vs Bind Mounts

Direct answer

Volumes are managed by the container engine (stored under its data directory); bind mounts map an existing host path into the container.

When to use this

Use it to choose how a container stores persistent data.

First 30 seconds

1. docker inspect <c> Mounts: type volume or bind?

2. Permissions match the container user?

3. SELinux: :z/:Z on bind mounts.

4. Backups cover the volume path.

5. Avoid binding sensitive host paths.

Operational verification

volume or host path → mounted at container path

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Docker / containerd / Podman / Kubernetes / OCI-compatible platforms
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.

PlatformDocker / containerd / Podman / Kubernetes / OCI-compatible platforms
Scope / prerequisiteUse it to choose how a container stores persistent data.
What next?2 suggested next steps
Evidence0
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.

2 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 How to verify Verify boundary

Write a test file inside the container, recreate the container, and confirm the file remains. For bind mounts, confirm the host directory exists before the container starts and that the container UID can write to it.

Step 2 Common failures Narrow the fault

A bind mount over a directory hides the image content at that path. Permission denied often means the host directory is owned by a different UID than the container user. Removing a container with docker rm -v deletes anonymous volumes.

Key points

Volumes are portable and safer for most data; bind mounts suit config files and development. Bind mounts expose host paths and need matching ownership and SELinux labels.

Key checks
  • docker ps -a — containers and exit codes
  • docker logs <c> — container output
  • docker inspect <c> — config, mounts, network, state
ReferenceWhat it is1 section · depth on demand

How it works

A named volume lives under /var/lib/docker/volumes by default. When an empty volume is mounted over a directory that has content in the image, Docker copies that content into the volume first; bind mounts never do this. Volume drivers can place data on NFS or other storage.

ReferenceImportant terms & boundaries3 sections · depth on demand

Volumes vs bind mounts

VolumeBind mounttmpfs
Managed byDockerHost pathMemory
Location/var/lib/docker/volumes/Any host pathRAM
PortableYesNo—
UseDatabases, persistent app dataConfig files, developmentSecrets, scratch
docker volume create pgdata
docker run -v pgdata:/var/lib/postgresql/data postgres:17
docker run -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro nginx

In depth

Decision rule

  • Data the application owns (database files, uploads) → named volume.
  • Files you edit on the host (config during development, source code) → bind mount.
  • Scratch data that must not touch disk (secrets, caches) → tmpfs.

Behaviour that surprises people

SituationNamed volumeBind mount
Mounted over a directory that has content in the imageEmpty volume is pre-filled with that contentHost directory hides the image content
Host path missingn/a-v creates an empty root-owned directory; --mount fails with an error
Removed with docker rmNo (only with -v or docker volume rm)Never
SELinux hostsLabelled automaticallyNeeds :z (shared) or :Z (private) relabel

Ownership

Files written in a volume or bind mount carry the container process's numeric UID. If the image runs as UID 999 and the host directory is owned by UID 1000, writes fail with permission denied. Fix the ownership on the host, run the container with a matching --user, or use a named volume and let the image initialise it.

Worked backup of a named volume

docker run --rm -v pgdata:/data:ro -v "$PWD":/backup alpine \
  tar czf /backup/pgdata-$(date +%F).tgz -C /data .

For a running database, a file copy like this is only consistent if the database is stopped; otherwise use the database's own dump or backup tool.

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

Common mistakes

  • Bind mounts with wrong ownership/SELinux labels.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
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
volumes vs bind mountsdocker volume bind mountcontainer persistent data
Confirmation

Confirm action

Continue?