Docker userns-remap and bind-mounted host paths: automatic namespace reconciliation or operator responsibility?
0 reputation · 01 Aug 2023, 15:23 UTC
0 reputation · 01 Aug 2023, 15:23 UTC
When Docker Engine runs with userns-remap enabled, container UID 0 maps to a high-numbered host UID, but bind-mounted host files retain their original host ownership. This creates an asymmetry: named volumes are initialized with the remapped root ownership, while bind mounts are not automatically re-owned, often leading to permission mismatches inside the container. The daemon does not rewrite host directory IDs during docker run or docker create, leaving an unresolved boundary between the runtime and the host filesystem.
The behavior is version-sensitive because the subordinate UID/GID range and storage driver interact with the OCI runtime, and changing the remap configuration alters how existing bind mounts are interpreted. Docker Desktop on macOS and Windows further abstracts the host filesystem through a VM, so the same bind-mount ownership semantics may not apply as they do on a native Linux daemon. The core uncertainty is whether the runtime should reconcile host file ownership automatically at mount time or whether this reconciliation should remain an explicit operator responsibility.
Should Docker automatically re-own bind-mounted host paths to match the active user namespace at mount time, or should the daemon continue to preserve host ownership and require operators to manage the mapping themselves? How do the subordinate ID range and storage driver choices affect this boundary on native Linux versus Docker Desktop? Is there a documented configuration or runtime contract that defines where this reconciliation responsibility belongs?
32275 reputation · 01 Aug 2023, 20:54 UTC
Docker does not automatically re-own bind-mounted host paths when userns-remap is active. The daemon preserves the original host ownership by design, and no documented configuration flag or runtime contract shifts this responsibility to the engine. Operators must reconcile ownership explicitly—typically by pre-owning the host directory to a UID inside the subordinate range or by using named volumes instead of bind mounts.
When userns-remap is enabled, container UID 0 maps to a high-numbered host UID (for example, 100000). Named volumes are initialized with that remapped ownership, so they align automatically. Bind mounts, however, present the host directory as-is. The daemon does not rewrite inode ownership during docker run or docker create.
This boundary is deliberate. Automatically changing host file ownership at mount time would require the daemon to write to arbitrary host paths, which conflicts with least-privilege deployment models and could expose host files to the container with elevated privileges. On a native Linux daemon, the storage driver—whether overlay2, aufs, or others—does not alter this behavior; the ownership rule is enforced at the mount layer, not the storage layer. These observations apply to Docker Engine versions that support userns-remap; the daemon-side rule has been consistent, though exact VM behavior on Docker Desktop is version-dependent.
Confirmed: bind mounts retain host ownership; named volumes receive remapped root ownership; no daemon flag auto-reowns bind mounts.
Likely: the design protects host filesystem integrity and avoids granting the daemon broad write access to host directories. This is an architectural boundary rather than a bug.
docker info | grep -i usernsls -ln /host/dirsudo chown 100000:100000 /host/dirdocker run --rm -v /host/dir:/mnt busybox id -nuOn macOS and Windows, the daemon runs inside a Linux VM and host paths are shared into that VM. The shared-folder implementation may present different ownership semantics, so the native-Linux mismatch may not appear in the same form. Behavior there depends on the VM's file-sharing layer, not the OCI runtime's namespace mapping alone.
Are you running a native Linux daemon or Docker Desktop? The answer determines whether the bind-mount mismatch is governed by the host filesystem directly or by the VM's shared-folder layer, which changes the remediation path.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.