Types of Mounts in Docker (Volumes, Bind Mounts, tmpfs)
Choose volumes, bind mounts, or tmpfs based on durability, sharing, and sensitivity.
In plain words
Choose storage by ownership: volumes for managed app data, binds for host integration/development and tmpfs for volatile or sensitive scratch state.
Think of it like…
A volume is a managed storage unit, a bind is a window into your desk, and tmpfs is a whiteboard that is erased when the room closes.
Where you’ve seen it
In practice, docker run --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data postgres:17; docker run --mount type=bind,src=$(pwd)/src,dst=/app/src web:dev is the concrete move for this job: choose volumes, bind mounts, or tmpfs based on durability, sharing, and sensitivity. The release is not accepted until docker inspect --format {{json .Mounts}} and compare Type, Source, Destination, RW and propagation confirms the result.
Words you’ll hear
- Volumes
- The implementation control in
docker run --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data postgres:17; docker run --mount type=bind,src=$(pwd)/src,dst=/app/src web:devfor choose volumes, bind mounts, or tmpfs based on durability, sharing, and sensitivity. - Bind Mounts
- The result to observe with
docker inspect --format {{json .Mounts}} and compare Type, Source, Destination, RW and propagation, rather than infer from a successful command alone. - tmpfs
- The production boundary exposed when mounting a host database directory into several unmanaged containers, or putting model checkpoints in tmpfs and expecting them after stop.
Visual diagram
Theory & deep dive
Volumes control path
The concrete mechanism is docker run --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data postgres:17; docker run --mount type=bind,src=$(pwd)/src,dst=/app/src web:dev. The observable result is docker inspect --format {{json .Mounts}} and compare Type, Source, Destination, RW and propagation; if those disagree, inspect the runtime evidence before changing unrelated settings.
Choose volumes, bind mounts, or tmpfs based on durability, sharing, and sensitivity. Keep Volumes, Bind Mounts and tmpfs in the same deployment record so the intent and the observed state cannot drift apart.
docker run --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data postgres:17; docker run --mount type=bind,src=$(pwd)/src,dst=/app/src web:dev
docker inspect --format {{json .Mounts}} and compare Type, Source, Destination, RW and propagation, not with command success alone.tmpfs failure boundary
A bind mount makes host UID, SELinux and path spelling part of the app contract. A volume decouples the container from the host directory but still needs backup, and tmpfs can consume RAM and trigger pressure if sized carelessly. The narrow failure to design for is mounting a host database directory into several unmanaged containers, or putting model checkpoints in tmpfs and expecting them after stop.
Accept this compromise explicitly: Volumes are portable inside Docker but opaque on the host; bind mounts are transparent and flexible but expose the machine’s filesystem. The controlled check-docker inspect --format {{json .Mounts}} and compare Type, Source, Destination, RW and propagation-also identifies the point where a different design is safer.
Exercise this failure safely: mounting a host database directory into several unmanaged containers, or putting model checkpoints in tmpfs and expecting them after stop.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: A bind mount makes host UID, SELinux and path spelling part of the app contract. A volume decouples the container from the host directory but still needs backup, and tmpfs can consume RAM and trigger pressure if sized carelessly.
- Intent
- Volumes
When to use it & trade-offs
What it is
Named and anonymous volumes are managed under Docker’s storage area and can use drivers; bind mounts directly expose a selected host path; tmpfs mounts live in memory in the container namespace and disappear when the container stops. Each has a different lifecycle and portability boundary.
Why it matters: A bind mount makes host UID, SELinux and path spelling part of the app contract. A volume decouples the container from the host directory but still needs backup, and tmpfs can consume RAM and trigger pressure if sized carelessly.
When to reach for it
- The fit is strongest for this job: choose volumes, bind mounts, or tmpfs based on durability, sharing, and sensitivity. Pair it with
docker inspect --format {{json .Mounts}} and compare Type, Source, Destination, RW and propagationin the runbook. - Production Volumes changes should make Bind Mounts observable through
docker run --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data postgres:17; docker run --mount type=bind,src=$(pwd)/src,dst=/app/src web:dev, rather than trusting the runtime default. - Keep a rollback example for the case where mounting a host database directory into several unmanaged containers, or putting model checkpoints in tmpfs and expecting them after stop.
When to avoid or be careful
- Do not accept command success while the system can still fail by mounting a host database directory into several unmanaged containers, or putting model checkpoints in tmpfs and expecting them after stop.
- Avoid erasing tmpfs protection merely to dodge this cost: “Volumes are portable inside Docker but opaque on the host; bind mounts are transparent and flexible but expose the machine’s filesystem”.
- Do not replace the evidence path-
docker inspect --format {{json .Mounts}} and compare Type, Source, Destination, RW and propagation-with a screenshot or a mutable tag.
docker run --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data postgres:17; docker run --mount type=bind,src=$(pwd)/src,dst=/app/src web:dev: practical choices
Strengths: Named and anonymous volumes are managed under Docker’s storage area and can use drivers; bind mounts directly expose a selected host path; tmpfs mounts live in memory in the container namespace and disappear when the container stops. Each has a different lifecycle and portability boundary.
Watch out: Volumes are portable inside Docker but opaque on the host; bind mounts are transparent and flexible but expose the machine’s filesystem.
Strengths: It can begin with docker run --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data postgres:17; docker run --mount type=bind,src=$(pwd)/src,dst=/app/src web:dev and fewer surrounding controls.
Watch out: It silently accepts mounting a host database directory into several unmanaged containers, or putting model checkpoints in tmpfs and expecting them after stop, which makes the result hard to reproduce after promotion.
Strengths: A bind mount makes host UID, SELinux and path spelling part of the app contract. A volume decouples the container from the host directory but still needs backup, and tmpfs can consume RAM and trigger pressure if sized carelessly.
Watch out: The platform adds an ownership and debugging layer; retain docker inspect --format {{json .Mounts}} and compare Type, Source, Destination, RW and propagation as the direct check.
Interview signals & numbers to know
When this topic comes up
- docker run --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data postgres:17; docker run --mount type=bind,src=$(pwd)/src,dst=/app/src web:dev
- docker inspect --format {{json .Mounts}} and compare Type, Source, Destination, RW and propagation
- Failure signature: mounting a host database directory into several unmanaged containers, or putting model checkpoints in tmpfs and expecting them after stop
- Trade-off: Volumes are portable inside Docker but opaque on the host; bind mounts are transparent and flexible but expose the machine’s filesystem.
Benchmarks & rules of thumb
- 3 mount types
- volume, bind and tmpfs
- 2 persisted classes
- managed volumes and host-backed binds
- 0 bytes on disk
- intended for a tmpfs mount
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
docker run --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data postgres:17; docker run --mount type=bind,src=$(pwd)/src,dst=/app/src web:devas proof and skippingdocker inspect --format {{json .Mounts}} and compare Type, Source, Destination, RW and propagation. - Mounting a host database directory into several unmanaged containers, or putting model checkpoints in tmpfs and expecting them after stop
- Optimizing Volumes without accepting that volumes are portable inside Docker but opaque on the host; bind mounts are transparent and flexible but expose the machine’s filesystem.
Likely interviewer follow-ups
- Why does
docker run --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data postgres:17; docker run --mount type=bind,src=$(pwd)/src,dst=/app/src web:devaddress Volumes here rather than through application code? - How would you distinguish healthy Bind Mounts from the failure “mounting a host database directory into several unmanaged containers, or putting model checkpoints in tmpfs and expecting them after stop” using
docker inspect --format {{json .Mounts}} and compare Type, Source, Destination, RW and propagation? - When would this trade-off-“Volumes are portable inside Docker but opaque on the host; bind mounts are transparent and flexible but expose the machine’s filesystem”-justify a different tmpfs design?
docker run --mount type=volume,src=pgdata,dst=/var/lib/postgresql/data postgres:17; docker run --mount type=bind,src=$(pwd)/src,dst=/app/src web:dev-and one proof-docker inspect --format {{json .Mounts}} and compare Type, Source, Destination, RW and propagation. Then name the boundary: mounting a host database directory into several unmanaged containers, or putting model checkpoints in tmpfs and expecting them after stop.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Types of Mounts in Docker (Volumes, Bind Mounts, tmpfs) with generative AI interview Q&A and hands-on practice.