Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 43/ 160
03. Storage, Volumes & Data Persistence

Types of Mounts in Docker (Volumes, Bind Mounts, tmpfs)

Choose volumes, bind mounts, or tmpfs based on durability, sharing, and sensitivity.

BeginnerVolumes · Bind Mounts3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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:dev for 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

Loading interactive 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.

Concrete Volumes setup

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

Key takeaway: Prove Bind Mounts with 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.

Deliberate failure test

Exercise this failure safely: mounting a host database directory into several unmanaged containers, or putting model checkpoints in tmpfs and expecting them after stop.

Key takeaway: Volumes are portable inside Docker but opaque on the host; bind mounts are transparent and flexible but expose the machine’s filesystem.

How it works, step by step

Step 1 of 4
Design

1. 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.

Choose storage by ownership: volumes for managed app data, binds for host integration/development and tmpfs for volatile or sensitive scratch state.
Key numbers at this step
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 propagation in 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

Explicit Volumes
Best for: Choose volumes, bind mounts, or tmpfs based on durability, sharing, and sensitivity, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived Bind Mounts experiments with low blast radius.

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.

Managed tmpfs
Best for: Teams that centralize tmpfs policy across many workloads.

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:dev as proof and skipping docker 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:dev address 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Docker Storage Drivers (overlay2, btrfs, zfs)
Next topic
Creating & Managing Named Volumes (docker volume create, ls, inspect)