Skip to content

RootlessKit — the nesting layer behind rootless containers

How RootlessKit creates the user-namespace, mount-namespace, and network-namespace sandbox that rootless Podman and Docker depend on — with the nesting pattern explained.

RootlessKit is the small Go binary that does the namespace-and-mount setup work for rootless Docker, rootless containerd, and rootless Podman when they need to spin up a fresh sandbox. It is the layer that translates “run an entire container engine as a non-root user” into the right clone() flags, the right newuidmap calls, and the right user-space network stack glue. Understanding it is how you debug why a rootless engine is mysteriously broken on a kernel that should work.

How to verify

A working RootlessKit is usually invisible — it sits beneath your rootless engine. To see it directly:

which rootlesskit
rootlesskit --version
ps -ef | grep rootlesskit
cat /proc/$(pgrep rootlesskit)/uid_map 2>/dev/null
cat /proc/$(pgrep rootlesskit)/status | grep -E "Uid|Gid"
rootlesskit --help | head -20

When you start dockerd-rootless.sh, you can see RootlessKit in the process tree owning the user-namespace that everything else runs in.

What’s happening

Running a container engine as a non-root user requires creating a user namespace where the user is mapped to UID 0, then creating a mount namespace where the engine’s image store, container roots, and overlay mounts can live without affecting the host, then creating a network namespace where the engine can manage interfaces without CAP_NET_ADMIN on the host. Doing all this correctly — with the right subuid/subgid ranges, the right pivot_root, the right network plumbing — is what RootlessKit does in one shot.

The output is a “rootless sandbox”: a set of nested namespaces where, inside them, the user appears as UID 0 with full namespace-local capabilities, but outside (from the host’s view) it is still the original unprivileged UID. Within this sandbox, dockerd or containerd or buildkitd can run as if it were root, manage interfaces, mount overlays, and start child containers — all without any privileged operations crossing back to the host.

The network is the trickiest part. RootlessKit ships two backends: slirp4netns (the universal but slow one — TCP/IP stack in user space) and pasta (the faster modern one — uses TAP devices and host kernel forwarding more efficiently). On any modern host, pasta is preferred — the throughput difference is 5-10x for typical workloads.

The mental model

Picture the layers for rootless Docker:

user shell (UID 1000)
└── dockerd-rootless.sh
    └── rootlesskit               (creates namespaces)
        ├── newuidmap/newgidmap   (writes UID maps)
        ├── pasta or slirp4netns  (user-space network stack)
        └── dockerd               (sees itself as UID 0, manages containers)
            └── containerd
                └── runc
                    └── nginx (UID 0 → 100000 on host)

The whole stack lives in the user namespace RootlessKit created. The host sees only one process — rootlesskit — as the root of the entire engine. Kill rootlesskit and the entire rootless engine and all its containers vanish.

Operational notes

  • Network backend choice. Default is pasta on Linux kernel ≥ 5.16, slirp4netns on older. Override with --net=pasta or --net=slirp4netns. Always prefer pasta for throughput-sensitive workloads.
  • Port-driver choice. Three options: builtin (slow, universal), slirp4netns (medium), pasta (fast — uses kernel-level TCP-MSS clamping and SO_REUSEPORT). Match this to the network backend.
  • MTU caveat. The default MTU inside the sandbox is 1500. If the host’s outbound interface has a lower MTU (typical for VPN, overlay networks, some clouds), TCP retransmits inside the sandbox skyrocket. Pass --mtu=1450 or whatever matches your host.
  • subuid range size. Need at least 65 536. Some workloads (Kubernetes nested in rootless, multi-tenant CI) want 524 288 or more. RootlessKit cannot exceed what /etc/subuid allows.
  • State directory. RootlessKit keeps its sandbox state in $XDG_RUNTIME_DIR/rootlesskit/ — typically /run/user/<uid>/rootlesskit/. This evaporates at logout unless loginctl enable-linger is set.
  • Nested rootless. RootlessKit can nest itself. Useful for rootless containers that themselves run rootless container engines (rootless Kubernetes-in-Docker, rootless GitLab runners). The cost is two layers of user namespaces, two layers of network indirection, and noticeably reduced performance.

Common pitfalls

  • Starting rootless Docker on a kernel without user_ns enabled. RootlessKit fails with “newuidmap: write to uid_map failed: Operation not permitted” — the kernel must have CONFIG_USER_NS=y.
  • Confusing RootlessKit’s user namespace with Podman’s. They serve the same purpose but the engines use them differently — RootlessKit’s sandbox is owned by dockerd/buildkitd; Podman’s user namespace is per-container.
  • Forgetting that the sandbox dies with its rootlesskit process. SIGKILL the wrong PID and the entire rootless Docker engine, with every container, evaporates instantly.
  • Running on a host where the user has no loginctl enable-linger and no manual XDG_RUNTIME_DIR set. After logout, the sandbox state directory is removed by systemd and the rootless engine cannot recover.
  • Picking slirp4netns on a modern kernel and accepting bad network performance. Always check what backend is active with rootlesskit --info and switch to pasta if available.

Stack Harbor uses RootlessKit’s behaviour to debug client incidents where rootless container engines act strangely — see managed operations for the per-host RootlessKit configuration we standardise, the pasta-preferred policy, and the subuid range sizing rules we apply across multi-tenant rootless fleets.