Chapter 21Lesson 01~120 minutes

Bind Mounts, Read-Only Mounts, tmpfs, Mount Propagation, Subpaths, SELinux Labels, and Host Coupling: Concepts, Architecture, and Mental Model

Model host-coupled mounts as explicit authority over daemon-host paths, mount namespaces, propagation, LSM labeling, and ephemeral memory-backed state.

Bind mountsHost couplingtmpfsNamespacesRead-only

Learning objectives

  • Explain why a bind mount grants a container direct authority over a daemon-host path rather than creating Docker-managed storage.
  • Distinguish source, target, read/write mode, propagation, SELinux labeling, tmpfs size/mode, ownership, and remote-daemon identity.
  • Inspect mount state before changing files and identify which machine actually owns a bind source path.
  • Contrast bind mounts, named volumes, tmpfs, and mount-type-specific subpath features without treating them as interchangeable.
  • Connect mount choices to portability, least privilege, host side effects, and reproducible operations.
Chapter 21 principle. A bind mount is a host authority decision. The source path belongs to the Docker daemon host; making it writable gives the container permission to change that host path. tmpfs is different: it is temporary memory-backed state that disappears with the container.

1. The practical problem: storage convenience can become host authority

Chapter 20 separated persistent data from the container lifecycle with Docker-managed volumes. Bind mounts solve a different problem: they expose a path that already exists on the daemon host directly inside a container. That is ideal for source-code editing, test fixtures, local configuration, and selected host integrations, but it couples the workload to a particular host filesystem layout and permission model.

The important question is not merely “is there a mount?” It is: which host path, on which daemon host, with what write authority, under what Linux security labeling and propagation rules, and for how long?

2. Mental model: daemon-host path → mount policy → container namespace → side effect

The Docker client submits a mount specification to the daemon selected by the active context. For a bind mount, the daemon resolves the source on its own host. The runtime places that source at a target inside the container mount namespace. Read-only mode can block container writes; propagation can control visibility of nested mounts on supported Linux hosts; SELinux may authorize or deny the access based on labels; and user IDs still govern ordinary filesystem permission checks.

Mount authority and visibility
flowchart TD
  C[Docker client + active context] --> D[Docker daemon host]
  D --> S[Source path on daemon host]
  S --> M[Mount configuration target + ro/rw + propagation]
  M --> L[LSM + UID/GID policy]
  L --> N[Container mount namespace]
  N --> A[Application access]
  A --> H[Host-visible side effect for writable bind]
  D --> T[tmpfs allocation]
  T --> N
  T --> X[Discarded when container stops/removes]
            

3. State to identify before any mutation

State Evidence Why it matters
Active context / daemon host docker context show, docker context inspect A bind source is resolved on the daemon host, not necessarily the client workstation.
Source and target docker inspect ... .Mounts Shows the host-side source and in-container destination.
Read/write authority RW field, mount mode Writable binds can create, change, or delete host files.
Propagation Propagation in inspect Default is rprivate; other modes are Linux-only and specialized.
SELinux state Host getenforce where available; label option in configuration A correct Unix mode can still be denied by SELinux policy.
tmpfs limits Mount type, size/mode, container memory limit tmpfs consumes memory and disappears with the container.
Ownership Numeric UID/GID on host and in container Names may differ; kernel authorization is numeric.
Subpath contract Mount type and documented feature Current Docker clearly documents volume-subpath for volumes; a narrower bind is normally expressed by binding the narrower host path itself.

4. Read-only inspection first

Before mounting anything, confirm the context and the exact host path. Then inspect existing mounts without modifying them.

docker context show
docker context inspect "$(docker context show)" --format '{{json .Endpoints.docker.Host}}'

docker ps -a --format 'table {{.ID}}	{{.Names}}	{{.Image}}'

docker inspect <container-name> --format '{{json .Mounts}}' 2>/dev/null || true

On a local Linux Engine, the daemon host may be the same machine as the client. On Docker Desktop, the daemon runs in a Linux VM and Desktop forwards approved native host paths. With a remote context, the remote daemon cannot directly bind files that exist only on the client.

5. Bind, volume, and tmpfs solve different state problems

Mount type Who supplies storage? Lifetime Typical use Primary risk
Bind Existing daemon-host path Host-controlled Source code, fixtures, selected config Host coupling and host-side writes
Named volume Docker volume driver Independent of container Persistent application state Unclear ownership/backup if unmanaged
tmpfs Kernel memory Container lifetime Ephemeral secrets/scratch/runtime files Memory pressure and non-persistence

A read-only bind reduces write authority but does not remove information exposure: the container can still read whatever the source contains. Least privilege therefore means both narrow source scope and the least required access mode.

6. Why --mount is the safer teaching default

Current Docker documentation recommends --mount for clarity. By default, a missing bind source causes an error. The shorter -v form creates a missing source directory automatically, which can hide a typo. Engine 29.3 added the explicit bind-create-src option so source creation can be intentional even with --mount.

Intent Behavior
Existing source required Use --mount type=bind,src=...,dst=...; missing source fails.
Explicit source creation Use bind-create-src only when creation is truly intended and supported by the installed Engine.
Legacy short form -v host:container auto-creates a missing host directory; inspect afterward to catch mistakes.

7. tmpfs is ephemeral and memory-accounted

A tmpfs mount has no source path. Files live in host memory and disappear when the container stops. Current Docker documentation notes that tmpfs usage counts against the container memory cgroup limit; a large tmpfs size does not bypass memory governance.

8. SELinux labeling is not a permissions shortcut

On SELinux-enabled Linux hosts, z means shared relabeling for content used by multiple containers, while Z means private relabeling. These options modify labels on the host path itself, so they should never be applied casually to broad system directories. If SELinux denies access, diagnose labels and policy rather than disabling SELinux.

9. DevOps connection: make host coupling visible

A reproducible workload records the daemon context, source path contract, target, write mode, security labeling assumptions, ownership, and platform-specific file-sharing behavior. The image digest alone cannot reproduce a workload whose correctness depends on an undeclared host directory.

Next lesson

Next: Bind Mounts, Read-Only Mounts, tmpfs, Mount Propagation, Subpaths, SELinux Labels, and Host Coupling: Guided Hands-On Workflow and Core Operations

Build a disposable mount lab that proves read-only versus writable authority, strict versus auto-created sources, tmpfs lifetime, mount inspection, and subpath boundaries.

Knowledge check

Where is a bind-mount source resolved?

Why is a read-only bind safer than a writable bind?

What is the default bind propagation mode?

Does tmpfs survive container removal?

Why can a bind mount work on Docker Desktop even though the daemon runs in a VM?

Official references and version notes

Version baseline, verified 2026-09-21.

Docker Engine 29.8.1 and Docker Desktop 4.91.0 are current; Compose 5.5.1, Buildx 0.37.1, and BuildKit 0.33.0 are the upstream baselines used for compatibility discussion. The labs record the learner's actual versions because host kernel, Docker Desktop VM/file-sharing mode, SELinux, and remote-context topology materially affect mount behavior.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this address.