Docker user namespaces: remap container root to a host user
Answer: Linux namespaces provide isolation for running processes and limit access to system resources.
Why remap
Running the application as an unprivileged user is the best way to prevent privilege-escalation attacks from within a container.
If processes must run as the root user within the container, remap that user to a less-privileged user on the Docker host.
The Docker daemon still runs as root when userns-remap is on.
How IDs are assigned
Two files handle the remapping: subuid and subgid, both under etc.
Each entry assigns a subordinate user ID range, then the next integers in sequence.
The start of that range is mapped within the namespace as UID 0 (root).
Enable it by starting dockerd with the userns-remap flag, or configure the daemon using the daemon.json file.
See also
Claims
- id: C1 claim: Linux namespaces isolate running processes. source: S1 evidence: "Linux namespaces provide isolation for running processes"
- id: C2 claim: Container root can be remapped to a less-privileged host user. source: S1 evidence: "re-map this user to a less-privileged user on the Docker host"
- id: C3 claim: Remapping is handled by two files, including subuid. source: S2 evidence: "The remapping itself is handled by two files"
- id: C4 claim: The first ID in the range is mapped within the namespace. source: S2 evidence: "mapped within the namespace"
Sources
- [S1] Isolate containers with a user namespace. Docker Docs. https://docs.docker.com/engine/security/userns-remap/ . License: Apache-2.0. Accessed 2026-11-24.
- [S2] Isolate containers with a user namespace (source). Docker documentation source. https://raw.githubusercontent.com/docker/docs/main/content/manuals/engine/security/userns-remap.md . License: Apache-2.0. Accessed 2026-11-24.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker Docs, Isolate containers with a user namespace; Docker documentation source, Isolate containers with a user namespace (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker Docs, Isolate containers with a user namespace; Docker documentation source, Isolate containers with a user namespace (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc.
Cite this
iinventedlight. 2026. "Docker user namespaces: remap container root to a host user." iinventedlight Library, iil:note:epy6czsb, version of 2026-11-24. https://iinventedlight.com/library/notes/docker-userns-remap/. License: CC-BY-4.0.
@misc{iil_note_epy6czsb,
author = {{iinventedlight}},
title = {{Docker user namespaces: remap container root to a host user}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-24},
url = {https://iinventedlight.com/library/notes/docker-userns-remap/},
note = {Permanent ID iil:note:epy6czsb. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- docker-userns-remap.schema.json (schema; CC-BY-4.0)
- docker-userns-remap.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-userns-remap.md.