Skip to content

runc internals — what actually runs your container

A field guide to runc, the OCI low-level runtime that Docker, containerd, and CRI-O all shell out to. Inspect specs, debug stuck containers, and understand the namespaces it builds.

When a container starts on a Linux host, the program that actually calls clone(), sets up the namespaces, mounts the rootfs, and finally execve()s the entrypoint is almost always runc. Docker delegates to containerd, containerd shells out to a per-container shim, the shim invokes runc with a JSON spec — and runc does the rest. Knowing how to inspect that layer turns “the container won’t start” mysteries into a five-minute diagnosis.

How to verify

Find which runtime is in use, list live runc containers, and inspect one:

docker info | grep -i runtime
containerd --version
runc --version

# List runc-managed containers (uses /run/containerd/runc/k8s.io by default)
sudo runc --root /run/containerd/runc/k8s.io list
sudo runc --root /run/containerd/runc/k8s.io state <container-id>

# Print the OCI spec for a running container
sudo cat /run/containerd/io.containerd.runtime.v2.task/k8s.io/<id>/config.json | jq .

If docker info shows runc plus extras like crun or kata, the daemon may be routing some workloads to alternative runtimes. The --root path varies — Docker uses /run/docker/runtime-runc/moby, Kubernetes via containerd uses /run/containerd/runc/k8s.io.

What’s happening

runc is a small Go program that implements the OCI Runtime Specification. It reads a config.json (the runtime spec) plus a rootfs directory and turns them into a running process. The runtime spec is the canonical, vendor-neutral description of “what is a container” — namespaces, cgroups, capabilities, seccomp profile, mounts, hooks, and the process to exec.

The lifecycle is small enough to fit in your head:

  1. create — runc parses the spec, sets up namespaces and cgroups, mounts the rootfs, and forks a process that blocks waiting to be started. At this point the container exists but isn’t running.
  2. start — runc tells the blocked process to execve() the entrypoint. The user workload now runs.
  3. kill — runc sends a signal to the container’s init process (PID 1 inside the namespace).
  4. delete — runc tears down cgroups, unmounts, and removes runtime state.

Higher-level runtimes (containerd, CRI-O) sit on top, providing image management, networking, snapshotters, and the CRI/CRI-O API. runc itself does none of that. This separation is why you can swap runc for crun (C implementation, faster startup), youki (Rust), or gVisor’s runsc (userspace kernel for sandboxing) with no change to Docker or Kubernetes.

The containerd-shim process is the parent of every running container. It outlives runc invocations and is what holds the container’s stdio, exit status, and forwarded signals. If you kill containerd, your containers keep running because each shim is independent.

The procedure

  1. Print the full OCI spec for a running container — this is the ground truth, regardless of what docker inspect or kubectl describe shows:
CID=$(docker ps -q | head -1)
RUNTIME_PATH=/run/docker/runtime-runc/moby
sudo runc --root $RUNTIME_PATH state $CID | jq .

The state output includes the container PID on the host. Once you have that PID, every standard Linux tool works:

PID=$(sudo runc --root $RUNTIME_PATH state $CID | jq -r .pid)
sudo ls -l /proc/$PID/ns/        # namespaces in use
sudo cat /proc/$PID/cgroup       # cgroup membership
sudo cat /proc/$PID/status | grep -E 'Cap|Seccomp|NoNew'
  1. Inspect what namespaces the container actually got. Compare each namespace inode against the host’s — any that match are shared, not isolated:
sudo readlink /proc/$PID/ns/net   /proc/1/ns/net
sudo readlink /proc/$PID/ns/pid   /proc/1/ns/pid
sudo readlink /proc/$PID/ns/user  /proc/1/ns/user

If the network namespace matches host PID 1’s, the container is running with --network host. If user namespaces are not enabled, the container’s root is the host’s root (subject to capabilities) — see Docker user namespaces for the fix.

  1. Diagnose a container that fails to start. The shim’s logs are the most useful trail:
sudo journalctl -u containerd --since "10 minutes ago" | grep -i $CID
sudo cat /run/containerd/io.containerd.runtime.v2.task/k8s.io/$CID/log.json

A common failure is mount: permission denied for a volume — usually a SELinux or AppArmor label mismatch. Another is exec format error, which means the image is for a different architecture (an arm64 image pulled onto an amd64 host).

  1. Run runc directly to reproduce an issue without the orchestrator. Create a minimal bundle:
mkdir -p /tmp/bundle/rootfs
cd /tmp/bundle
sudo runc spec
sudo docker export $(sudo docker create alpine) | sudo tar -C rootfs -xf -
sudo runc run test-container

Edit config.json between runs to isolate which spec field is causing the problem. This is invaluable when debugging seccomp profiles, AppArmor labels, or unusual mount options.

  1. Force-kill a stuck container that docker rm -f won’t remove. Sometimes the containerd shim hangs and refuses to clean up:
sudo runc --root $RUNTIME_PATH list
sudo runc --root $RUNTIME_PATH kill <id> KILL
sudo runc --root $RUNTIME_PATH delete -f <id>

If runc itself reports “container does not exist” but Docker still lists it, the daemon state is out of sync — restart containerd to resync.

  1. Swap to a faster runtime when startup latency matters. Install crun and register it with Docker:
sudo apt install crun
# /etc/docker/daemon.json
{
  "runtimes": {
    "crun": { "path": "/usr/bin/crun" }
  }
}
sudo systemctl restart docker
docker run --runtime=crun --rm alpine echo hi

crun typically starts containers 2-3x faster than runc on workloads that create many short-lived containers (CI jobs, lambda-style functions).

Common pitfalls

  • Editing config.json of a running container has no effect — the spec is parsed at create time. Re-create the container to apply changes.
  • runc requires CAP_SYS_ADMIN on the host (or rootless mode with user namespaces configured). Running as a non-root user without the rootless setup fails opaquely.
  • Mismatched --root paths between runc invocations and the calling runtime cause “container does not exist” errors. Match the orchestrator’s path: /run/docker/runtime-runc/moby for Docker, /run/containerd/runc/k8s.io for K8s.
  • The shim’s log file (log.json) is line-delimited JSON, not plain text. Use jq to parse it or you’ll miss multi-line errors.
  • Older runc versions (<=1.0.0) had a notorious CVE-2019-5736 host-escape bug. Always check runc --version on legacy hosts and patch.

We treat the runc layer as a first-class debugging surface for every container platform we operate. When a Kubernetes pod refuses to start and the controller manager is unhelpful, dropping down to runc state inspection answers the question in minutes instead of hours — one of the diagnostic habits behind our managed operations practice.