← All writing

Inside Container Runtimes: From Docker to containerd, CRI-O, and runc

· Sourabh G Kulkarni

What actually executes your container when Kubernetes runs a pod: the evolution from the Docker daemon to containerd, CRI-O, and low-level OCI runc.

Inside Container Runtimes: From Docker to containerd, CRI-O, and runc

When a Kubernetes kubelet receives an instruction to run a pod, what actually happens on the Linux host?

Many engineers still say "Docker runs the container." But in modern Kubernetes (since v1.24), Docker has been completely removed from the cluster architecture.

To effectively debug low-level node crashes, zombie processes, and container breakout security issues, you need to understand the container runtime stack: CRI, high-level runtimes (containerd, CRI-O), and low-level runtimes (runc).

flowchart TD
    Kubelet["kubelet (Kubernetes Node Agent)"]
    
    subgraph HighLevel["High-Level Runtime (CRI Daemon)"]
        containerd["containerd / CRI-O"]
        ImageService["Image Puller & Snapshotter"]
    end

    subgraph LowLevel["Low-Level Runtime (OCI Compliant)"]
        runc["runc (CLI Tool)"]
    end

    subgraph Kernel["Linux Kernel Primitives"]
        Cgroups["cgroups (CPU/Memory Limits)"]
        Namespaces["namespaces (PID, NET, MNT Isolation)"]
    end

    Kubelet -->|gRPC via Container Runtime Interface| containerd
    containerd --> ImageService
    containerd -->|Spawns shim & executes| runc
    runc -->|Syscalls (clone, unshare, setns)| Kernel
    Kernel --> Cgroups
    Kernel --> Namespaces

1. The Container Runtime Interface (CRI)

Originally, Kubernetes had hardcoded logic to talk directly to the monolithic Docker daemon (dockershim). But Docker was built for human desktop use; it included volume management, swarm orchestration, and complex API daemons unnecessary for Kubernetes.

In Kubernetes 1.5, the community introduced the Container Runtime Interface (CRI): a gRPC API that allows Kubernetes to plug into any container runtime without knowing vendor details.

Today, two high-level CRI runtimes dominate production:

  1. containerd: Originally extracted from Docker, now an independent CNCF graduated project. Standard on EKS, GKE, and AKS.
  2. CRI-O: Built by Red Hat specifically for Kubernetes. Standard on OpenShift.

2. High-Level vs. Low-Level Runtimes

  • High-Level Runtime (containerd, CRI-O): Manages the full lifecycle of containers. It pulls images over the network, unpacks filesystem layers, manages storage snapshotters, and oversees network namespaces.
  • Low-Level Runtime (runc): A lightweight CLI tool implementing the Open Container Initiative (OCI) runtime specification. It takes an unpacked root filesystem and a config.json specification, and makes the actual Linux kernel system calls to spawn the container. Once the container process starts, runc exits!

3. What is a Container Really? (Linux Kernel Primitives)

There is technically no such thing as a "container" inside the Linux kernel. A container is simply a standard Linux process isolated by two kernel features:

A. Linux Namespaces (What the Process Can See)

  • PID Namespace: Process isolation. The container process believes it is PID 1, while on the host it is PID 38942.
  • NET Namespace: Isolated loopback, IP addresses, and routing tables.
  • MNT Namespace: Mount point isolation (seeing its own container rootfs rather than the host /).
  • IPC, UTS, USER Namespaces: Isolating IPC message queues, hostnames, and user UID mappings.

B. Control Groups (cgroups) (What the Process Can Use)

Control Groups enforce resource quotas:

  • CPU shares & quotas: Ensures a container cannot consume 100% of host CPU.
  • Memory limits: Triggers the kernel OOM (Out of Memory) Killer when a container exceeds its memory allocation.

4. Useful Debugging CLI Tools on the Node

When SSH'd into a Kubernetes node, standard docker commands will fail. Use the native runtime CLIs:

# 1. List running containers using crictl (CRI CLI)
crictl ps

# 2. Inspect container logs directly from the node
crictl logs <container-id>

# 3. For containerd specific debugging
ctr --namespace k8s.io containers list

Understanding this stack demystifies Kubernetes errors: CrashLoopBackOff is an application failure inside namespaces; OOMKilled is a cgroup enforcement; and image pull errors belong to the high-level containerd snapshotter.