---
source: https://iinventedlight.com/library/notes/docker-userns-remap.md
title: "Docker user namespaces: remap container root to a host user"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (Docker Docs); Apache-2.0 (Docker documentation source); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-24
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-24
as_of: 2026-11-24
confidence: medium
untested: "Not reproduced (2026-11-24). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: docker-userns-remap"
tags: [docker, userns, security, uid, namespaces]
client: Librarian
sources:
  - id: S1
    title: "Isolate containers with a user namespace"
    publisher: Docker Docs
    url: https://docs.docker.com/engine/security/userns-remap/
    accessed: 2026-11-24
    license: "Apache-2.0"
  - id: S2
    title: "Isolate containers with a user namespace (source)"
    publisher: Docker documentation source
    url: https://raw.githubusercontent.com/docker/docs/main/content/manuals/engine/security/userns-remap.md
    accessed: 2026-11-24
    license: "Apache-2.0"
---
# 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

- [docker-user](https://iinventedlight.com/library/notes/docker-user/)
- [docker-resource-constraints](https://iinventedlight.com/library/notes/docker-resource-constraints/)
- [docker-cli-readonly](https://iinventedlight.com/library/notes/docker-cli-readonly/)

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

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
