What is Docker userns-remap? Mapping container UIDs to unprivileged host IDs
Docker `userns-remap` maps user and group IDs (UIDs/GIDs) inside containers to a separate, unprivileged range on the host. A process that is UID 0 (`root`) in a container therefore uses a different numeric UID on the host. The Docker system daemon itself still runs as host root, so this is not the same boundary as rootless Docker.
What is Docker userns-remap? Mapping container UIDs to unprivileged host IDs
Docker userns-remap maps user and group IDs (UIDs/GIDs) inside containers to a separate, unprivileged range on the host. A process that is UID 0 (root) in a container therefore uses a different numeric UID on the host. The Docker system daemon itself still runs as host root, so this is not the same boundary as rootless Docker.
This guide covers the Linux system Docker Engine only. It does not cover Docker Desktop, rootless Docker setup, or Kubernetes Pod user namespaces. Enabling remapping on an existing daemon can affect storage and volume access; prefer a new installation or plan a maintenance window and recovery path.
What changes?
Linux user namespaces map UIDs/GIDs inside a namespace to IDs in its parent namespace. Docker uses subordinate ID ranges in /etc/subuid and /etc/subgid. For example, Docker documents testuser:231072:65536: the account receives 65,536 IDs starting at 231072, so container UID 0 maps to host UID 231072 and UID 1 to 231073. These are example values; choose a range that does not overlap existing assignments.
| Mode | Container IDs on host | Daemon privilege | Consider it when |
|---|---|---|---|
Docker userns-remap | Mapped to a separate unprivileged UID/GID range | The system daemon remains root | You need to remap container IDs under an existing rootful daemon |
| Rootless Docker | Mapped within the invoking user's namespace | Daemon and containers are unprivileged | The daemon itself must run without root |
Remapping does not make a compromised rootful daemon unprivileged. See the Docker rootless mode documentation if reducing daemon privilege is the goal.
Before enabling it
Confirm this is a system Docker Engine on Linux; service commands and paths vary by distribution and installation.
Back up `/etc/docker/daemon.json`, note the Docker data directory, running workloads, and recovery procedure. Merge settings into existing JSON; do not overwrite unrelated keys.
Check that `/etc/subuid` and `/etc/subgid` provide a valid, non-overlapping range for `dockremap` or the selected account. With `default`, Docker uses or creates `dockremap`.
Inventory bind mounts, external volume drivers, host PID/network namespace sharing, and privileged containers before changing the daemon.
On an existing installation, Docker can mask existing image/container layers and other objects beneath a remapped subdirectory of its data directory. They may appear unavailable; do not treat this as deletion or move/delete storage manually. This is why a fresh installation is the safer place to enable remapping.
Enable on a system daemon
The following requests Docker's default dockremap account and subordinate IDs. If the file already exists, merge this key into its valid JSON object:
{
"userns-remap": "default"
}On a typical systemd installation, restart Docker during a maintenance window. Confirm the service name and procedure for your distribution first.
sudo systemctl restart dockerIf startup fails, inspect the daemon log, JSON syntax, ID ranges, and file permissions. Restore the backed-up configuration if service recovery is urgent; do not delete the data directory while diagnosing.
Verify the mapping
Check the account and ranges, then use a disposable test container and directory. The configuration file alone does not prove that remapping is active.
getent passwd dockremap
grep '^dockremap:' /etc/subuid
grep '^dockremap:' /etc/subgid
docker run --rm alpine idTo verify host ownership, bind-mount an empty test directory, create a file from the container, and inspect it on the host with stat. The host UID/GID should reflect the mapped range and differ from the container's UID/GID. Never use a production data directory for this test.
If docker image ls changes, do not assume images were deleted: existing data may be masked under the remapped subtree. Avoid cleanup or manual moves until you have a recovery plan.
Compatibility and recovery
Bind-mounted files are accessed as the mapped host IDs. Prepare only the needed directory for those IDs; do not use broad chmod 777. Host PID or network namespace sharing may be incompatible. External volume drivers must support the mapped ownership. Privileged containers are restricted; Docker's --userns=host can opt a container out of remapping, but gives up that container's UID isolation and can affect filesystem ownership. Use it only for a specifically justified workload.
Removing the setting and restarting is not necessarily a simple rollback: resources created under remapping may not be visible or accessible in the old view. Preserve backups and ownership information, and follow Docker's recovery guidance. Do not merge, move, or delete storage subdirectories just because resources appear missing.
Consider userns-remap when you keep a rootful system daemon but want container IDs mapped away from host root. If the daemon must also be unprivileged, or workloads depend on host namespaces, privileged mode, or a volume driver, test compatibility first and compare rootless operation. Remapping is not a guarantee against container escape or a substitute for daemon security.
References
[Docker Engine: Isolate containers with a user namespace](https://docs.docker.com/engine/security/userns-remap/)
[Docker Engine: Rootless mode](https://docs.docker.com/engine/security/rootless/)
[Linux man-pages: user_namespaces(7)](https://man7.org/linux/man-pages/man7/user_namespaces.7.html)
Documentation checked on 2026-11-23. Verify exact procedures against your installed Docker Engine version and Linux distribution.