← All notes

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

Sources

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

Permanent ID: iil:note:epy6czsb

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.},
}

Markdown

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.

All artifact files (JSON index)

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.