There Is No Container: Docker Is Five Kernel Contracts in a Trenchcoat
readlink /proc/self/ns/pid prints pid:[4026531836]. That inode number is the entire container. There is no struct container in the kernel, no syscall that cr...
readlink /proc/self/ns/pid prints pid:[4026531836]. That inode number is the entire container. There is no struct container in the kernel, no syscall that creates one, and no field in task_struct that says "this process is containerized." What you call a container is five independent kernel subsystems that happen to be pointed at the same process — and each one has a different owner, a different failure mode, and a different line item on your latency budget.
Once you build a runtime yourself, the weirdness becomes a set of contracts. Here they are, in the order a container touches them.
A Container Has No Kernel Object, Only Namespace Memberships
The kernel answers exactly one question: which namespace inodes does this process share with the host? Container-ness is a membership test, not a flag. You can compute it from /proc without any Docker API at all.
package isolate
import (
"fmt"
"os"
"path/filepath"
"strings"
)
// ForeignNamespaces reports which namespaces of pid are not the caller's.
// A non-empty result means pid is isolated from us along those axes.
func ForeignNamespaces(pid int) (map[string]string, error) {
self, err := namespaceInodes("/proc/self/ns")
if err != nil {
return nil, fmt.Errorf("read caller namespaces: %w", err)
}
target, err := namespaceInodes(filepath.Join("/proc", fmt.Sprint(pid), "ns"))
if err != nil {
return nil, fmt.Errorf("read namespaces of pid %d: %w", pid, err)
}
foreign := make(map[string]string, len(target))
for kind, inode := range target {
if own, ok := self[kind]; !ok || own != inode {
foreign[kind] = inode
}
}
return foreign, nil
}
func namespaceInodes(dir string) (map[string]string, error) {
entries, err := os.ReadDir(dir)
if err != nil {
return nil, err
}
out := make(map[string]string, len(entries))
for _, e := range entries {
dst, err := os.Readlink(filepath.Join(dir, e.Name()))
if err != nil {
return nil, err
}
// symlink target looks like "pid:[4026531836]"
if i := strings.IndexByte(dst, '['); i >= 0 {
out[e.Name()] = dst[i+1 : len(dst)-1]
}
}
return out, nil
}
A kernel with every isolation feature enabled exposes eight of these: mount, PID, network, IPC, UTS, user, cgroup, and time. Docker 29.8.0 with default configuration creates a time namespace with zero offsets — a namespace that changes nothing observable, emitted because the OCI spec allows it and the runtime generated one. That is not an isolation decision; it is an unaudited default.
This is also why --pid=host is a security decision disguised as a boolean. Drop the PID namespace and the process sees the host's process table, so every /proc/<pid>/ path becomes a handle to something it should not reach. The isolation was never a wall; it was a different view of the same data structure.
The Root Filesystem Is a Mount Table Edit, Not a chroot
An image really is a directory tree, and the runtime really does make it your process's root. The interesting part is that chroot(2) is the wrong tool, and every runtime knows it.
chroot rewrites one field: the process's filesystem root in fs_struct. It does not touch the mount table. So a process holding CAP_SYS_CHROOT can call chroot again on a subdirectory, leave its working directory above the new root, and then walk out with cd .. — path resolution stops at the process root, but the root moved down while the CWD did not. That is the whole exploit, and it needs no kernel bug.
pivot_root(2) replaces the root mount instead of the root path. The new root has no parent in the mount tree, so .. has nowhere to go. The sequence is short but the ordering is load-bearing:
/* every step can fail; a container runtime that ignores one is not a sandbox */
if (chdir(new_root) != 0)
bail("chdir to new root");
if (syscall(SYS_pivot_root, ".", "old_root") != 0)
bail("pivot_root");
if (chroot(".") != 0)
bail("chroot after pivot_root");
if (umount2("/old_root", MNT_DETACH) != 0)
bail("detach old root");
rmdir("/old_root");
Note that chroot still appears — the two are not alternatives. pivot_root rearranges the mount namespace; the follow-up chroot(".") pins the process root to the same place, and the kernel's own implementation finds the filesystem to move by consulting the per-process root. new_root must also already be a mount point, which is why runtimes bind-mount the extracted image onto itself before pivoting.
The mount flags matter more than the syscall. MS_NOSUID stops a setuid binary inside the image from re-entering with privileges; MS_NODEV stops a writable /dev from becoming a handle to the host's block devices. Drop either and the root swap is decoration.
Where the folder lives is overlayfs: image layers stack as lowerdir, writes land in an upperdir, and the merged view is what you see. That is exactly why docker commit can produce an image from a running container — it packages the upperdir. It is also why a committed image inherits PID files, unix sockets, and half-written journals, the failure mode described in Git, Docker, and IPFS All Hide the Same Beautiful Idea. And the folder is not free: OverlayFS write throughput measures 0.11–0.15x a bind-mounted volume on SSD-backed storage, while metadata operations run 1.3–4.8x faster. Put your database on the overlay and you get the worst of both.
fork() Does Not Exist in Go, So the Runtime Is a C Constructor
The runtime that creates containers, runc, is written in Go. That is apparently a poor fit, and the reason is precise rather than stylistic: container setup needs a window in which the process is single-threaded, and a Go process is never single-threaded once the runtime is up.
clone(2) copies only the calling thread. In a Go binary the scheduler owns GOMAXPROCS OS threads plus sysmon plus GC workers, and the child of a raw clone has one thread, no scheduler, and no guarantee that any runtime lock is released. The window between clone and exec is only safe for async-signal-safe libc calls. But container setup needs setns, setuid, setgroups, and the uid/gid map writes — all of which must land before exec and none of which can safely run in a sick Go runtime.
runc resolves this by never letting the Go runtime start until the namespaces are settled. The nsenter package is cgo with a constructor, and constructors run from ELF .init_array — after the dynamic linker, before main, before the runtime spins up an M:
//go:build linux && !gccgo
package nsenter
/*
#cgo CFLAGS: -Wall
extern void nsexec();
void __attribute__((constructor)) init(void) {
nsexec();
}
*/
import "C"
// Importing this package for its side effects is mandatory: without the blank
// import, nsexec() never runs and the re-exec silently fails to join namespaces.
Any application that links libcontainer directly must import _ "github.com/opencontainers/runc/libcontainer/nsenter" for exactly that reason. If you skip the blank import, the re-exec succeeds, the container starts, and the process is simply in the wrong namespaces — a silent failure with no error path.
Inside nsexec(), the process reads the file descriptor number from _LIBCONTAINER_INITPIPE. Absent that variable, it returns immediately and Go boots normally; present, it reads the bootstrap record — namespace paths, clone flags, uid/gid mappings, console path — and starts cloning. It clones twice, producing three stages: the original runc process, a stage-1 child, and a stage-2 child tagged runc:[2:INIT]. Only the last one returns into the Go runtime; the others exit(0) after handing back a PID over a sync pipe.
Two constraints force the extra stage rather than one clone. A user namespace must exist before the other namespaces can be created without privilege, so it is joined first, in a separate pass — __join_namespaces(CLONE_NEWUSER, ...) precedes the rest. And CLONE_NEWPID only affects children: the caller of unshare cannot enter a new PID namespace, only the process it subsequently forks can. CLONE_PARENT on the final clone makes stage-2's parent the original runc run process rather than its short-lived intermediary, so SIGCHLD is delivered to the process that is actually waiting for it.
The missing-fork problem is solved with a re-exec: exec /proc/self/exe init with a private argv marker and a pipe fd in the environment. Same binary, different code path, no second helper to ship. The cost is that runc init is now a public entry point into container setup, reachable by anyone who can run the binary — which is exactly why the environment variable exists as a gate rather than a command-line flag.
Rootless Is a Network Stack You Now Own
Root is required for the historical reason that mount, mknod, and network configuration checked CAP_SYS_ADMIN against the initial user namespace. User namespaces change the arithmetic: inside a new userns the process gets a full capability set scoped to it, so it can mount, pivot, and create network namespaces unprivileged.
The exception is the host side of the network. Attaching a veth pair to the host bridge requires CAP_NET_ADMIN in the host network namespace, and a rootless process does not have it. So every rootless runtime moves the datapath into userspace, and the bill arrives as throughput. RootlessKit's iperf3 matrix, child to parent, July 2026:
lxc-user-nic— 49.1 Gbps at MTU 1500, 50.7 at MTU 65520 (kernel veth, setuid helper)- rootful veth (reference) — 49.3 / 50.8 Gbps
pasta— 0.24 / 31.9 Gbpsslirp4netns— 1.69 / 8.11 Gbpsgvisor-tap-vsock— 2.46 / 8.75 Gbpsvpnkit— 0.14 Gbps, no jumbo support
Read the pasta row twice. At jumbo MTU it is the second-fastest driver in the table; at standard Ethernet MTU it is six times slower than slirp4netns. The per-packet cost dominates at 1500 bytes, and pasta's advantage only materializes when it can move large frames through a small number of copies. A benchmark at one MTU tells you nothing about the other.
Concurrency inverts the ranking again. Against an HTTP workload, pasta leads slirp4netns by 48% at c=1 and 59% at c=4, ties at c=8, then loses by 74% at c=16 and 91% at c=32 — 15,166 req/s against 28,931. The maintainer's explanation is architectural: pasta is single-threaded, and libslirp has had years of multi-threaded tuning.
Port publishing is a second, separate tax. RootlessKit's port drivers, parent to child: slirp4netns 7.56 Gbps, builtin 29.3, implicit (pasta) 39.9, pesto 45.2 Gbps but IPv4-only and experimental, gvisor-tap-vsock 3.77.
The trade-off worth stating plainly: rootless does not remove the cost of isolation, it relocates it into a component you now patch. CVE counts over five years — libslirp 4 (two high), pasta 1 (low), bubblewrap 2 (one high). Ditching the Daemon covers the operational side of running this as a default rather than an experiment.
Then Bill the Primitives Separately From the Runtime
Once you decompose startup, the numbers rearrange everything you assumed about why containers are slow. On premium SSD, warm start across images from 5 MB to 155 MB varies by 2.5% — 554 to 568 ms. Namespace creation contributes 8–10 ms, under 1.5% of total. The kernel work you just read about in detail is nearly free; what you wait for is overlayfs mounting and image layer preparation.
Storage is the first multiplier: 1157 ms on standard HDD against 568 ms on premium SSD, a 2.04x penalty that widens to 2.28x for nginx and 2.41x for python. Hypervisor virtualisation is the second: Docker Desktop on macOS takes 1528 ms against 568 ms natively, 2.69x, reaching 3.28x for nginx, with 9.5x higher CPU-throttling variance.
Within the namespace budget, cost is not evenly distributed. A full five-namespace set measured 1.58 ms against a user-namespace-only baseline — roughly 19x — and the network namespace accounts for nearly all of it, because the kernel must construct an independent network stack with loopback and full protocol state. UTS and PID are essentially free; mount and IPC are moderate because the mount tree is duplicated. The price is paid entirely up front in clone, not on every later context switch.
That network namespace line item is also a kernel patch history. unshare -n true cost 47.7 ms in 2017 because teardown called synchronize_net() per netfilter hook. The fix moved hook freeing to call_rcu, and the same command dropped to 1.5 ms. Two orders of magnitude of container networking overhead lived in a single synchronisation call for years.
The honest comparison is a hand-built container in 81 lines of bash at 124 ms per create/destroy cycle against docker run --rm alpine at 518 ms. CPU time is comparable at 14 ms per run, so almost the entire gap is waiting — on veth setup, mount teardown, and the client-server hop through dockerd and containerd. Docker is not slow at containers. It is slow at the five things it adds around them.
Which is the practical rule for the next time a container misbehaves: name the layer before you name a fix. Wrong root filesystem, and you are looking at pivot_root, mount flags, or overlayfs — check whether the path is on the upperdir or a volume before blaming the app. Wrong PID 1, and it is the namespace plus signal delivery, which is why tini exists. Wrong throughput, and it is veth in the kernel or a single-threaded userspace forwarder, and the MTU decides which. Wrong start time, and it is storage, not isolation. There is no container object to inspect, so docker inspect, /proc/<pid>/ns, and lsns are the only map you get — and every one of them reports membership, never a thing.