Rootless container

Also known as: rootless mode

On this page 7

A rootless container is a container that is created and run by an unprivileged user account, with the container engine, runtime and workload all operating without root privileges on the host. In the field of containers and cloud infrastructure, rootless mode reduces the impact of a container escape: an attacker who breaks out lands in an ordinary user account rather than gaining control of the whole machine.

The technique relies primarily on Linux user namespaces, which map the root user inside the container to a regular, unprivileged user ID outside it. Podman was designed with rootless operation as a default use case, Docker supports a dedicated rootless mode, and runtimes such as runc and crun can run unprivileged.

How rootless containers use user namespaces

Rootless operation works by giving each container its own user namespace in which user IDs are translated. Inside the namespace, a process can run as UID 0 and perform administrative tasks such as installing packages, but the kernel maps that UID to an unprivileged host UID, for example 100000, which owns nothing important on the host.

To support images that contain several users, the host grants each account a range of subordinate IDs in /etc/subuid and /etc/subgid, commonly 65,536 IDs per user. The setuid helpers newuidmap and newgidmap write these ranges into the namespace mapping, which is the only step that requires elevated privilege, and it is tightly constrained.

The table below shows how identities translate in a typical configuration.

Identity inside containerMapped host identityEffective host privilege
UID 0 (root)UID 1000, the invoking userOrdinary user rights
UID 1 to 65535UID 100000 to 165534No rights beyond the mapped files
Unmapped IDsShown as nobody (65534)Cannot be written as owner
Example of user ID mapping in rootless mode

Because the kernel enforces the mapping, capabilities granted inside the namespace apply only to resources that the namespace owns. A container may change its own network configuration, yet it cannot load kernel modules or modify host files owned by real root.

Supporting components for networking and storage

Rootless containers need user-space replacements for privileged operations that a rootful engine performs directly. Creating virtual Ethernet pairs, configuring bridges and mounting overlay filesystems traditionally require root, so rootless stacks substitute helpers that run with the user’s own permissions.

The following table lists the main helpers and the problem each one solves.

ComponentProblem solvedNotes
slirp4netnsUser-mode networkingOlder default, extra CPU overhead
pastaUser-mode networkingDefault in Podman 5, better throughput
RootlessKitNamespace setup and port forwardingUsed by Docker rootless mode
fuse-overlayfsLayered storage without rootNeeded on kernels before 5.11
Native overlayfsLayered storage in user namespacesSupported from Linux 5.11
cgroup v2 delegationResource limits for the userDelegated through systemd
Components that enable rootless operation

Resource limits depend on cgroup v2 with systemd delegation. On hosts still running cgroup v1, rootless containers generally cannot enforce CPU or memory limits, which is a frequent surprise when migrating workloads.

Rootless containers compared with other isolation approaches

A rootless container is not the same as a container that runs as a non-root user. Setting USER in a Dockerfile changes the identity of the workload, but the daemon may still run as root on the host. Rootless mode removes root from the engine itself, which closes a wider class of attacks, including abuse of the Docker socket.

The comparison below places rootless mode among related isolation options.

ApproachEngine runs as rootEscape impactTypical overhead
Rootful containerYesPossible full host compromiseLowest
Non-root user in containerYesReduced, engine still privilegedLowest
Rootless containerNoLimited to one user accountLow, mainly networking
User namespace remappingYesReduced by UID mappingLow
Kata ContainersVariesContained by a lightweight VMModerate
Isolation approaches for container workloads

These approaches can be layered for defense in depth. Running a non-root workload inside a rootless container, with a distroless image and a seccomp profile, leaves an attacker very few useful primitives even after exploiting an application bug.

Practical use and configuration choices

Rootless containers are most valuable on shared hosts, developer workstations and CI runners, where many people or jobs start containers and none should gain root. They also suit build pipelines that use Buildah or Podman to produce images without a privileged daemon.

  • Allocate subordinate ID ranges for every user who runs containers, avoiding overlaps between accounts.
  • Enable lingering with loginctl enable-linger so that user services survive logout.
  • Prefer pasta or native overlayfs on recent kernels for better network and storage performance.
  • Publish high ports such as 8080 and forward from 80 with a proxy, or lower net.ipv4.ip_unprivileged_port_start deliberately.
  • Generate systemd units or Quadlet files to start rootless containers at boot.

In Kubernetes, the equivalent idea appears as user namespace support for pods, enabled through the hostUsers: false field, and as running the kubelet and runtime in rootless mode, which remains less common in production clusters.

Limitations, risks and common mistakes

Rootless mode reduces risk but does not eliminate it. Kernel vulnerabilities reachable through user namespaces have historically allowed privilege escalation, and some distributions restrict unprivileged user namespaces for that reason. Patch levels and namespace policies therefore remain part of the security posture.

The table below summarizes typical problems and their fixes.

SymptomCauseFix
Cannot bind port 80Ports below 1024 are privilegedUse a high port or adjust the sysctl
Files owned by odd UIDs on volumesSubordinate ID mappingUse --userns=keep-id or chown in namespace
Memory limits ignoredcgroup v1 or no delegationEnable cgroup v2 with systemd delegation
Slow network throughputslirp4netns overheadSwitch to pasta
Containers stop at logoutUser session endsEnable lingering for the account
Common rootless container issues

Some workloads cannot run rootless at all, notably those that need to load kernel modules, manage host networking or access raw devices. For such cases, a rootful engine with tight policies or a virtual machine remains the appropriate choice.

The short version

Picture an apartment building where each tenant can rearrange furniture and change locks inside their own apartment, but holds no key to the building’s boiler room. A rootless container works the same way. Inside, the program feels fully in charge; outside, it is just an ordinary guest of the computer.

If something goes wrong and a program breaks out of its container, it finds itself with only the rights of a regular user, not the master key to the whole machine. That simple limit makes containers much safer on shared systems.

Where it makes a difference

A university computing department offers a shared Linux server where about 200 students build and test containerized projects. Giving students access to a root-owned Docker daemon would effectively make each of them an administrator of the server, because anyone who controls the daemon socket can mount the host filesystem.

The administrators install Podman, assign each student a separate range of 65,536 subordinate IDs, enable cgroup v2 delegation and set per-user memory limits of 4 GB. Students run containers exactly as they would on their laptops, publishing web applications on ports above 8000. When one student’s container is compromised through an outdated library, the attacker gains only that student’s account, and no other user or system file is affected.