Container Runtime Shim: Decoupling the Container Lifecycle
A runtime shim is a small process that decouples the container daemon (like containerd) from the container itself. This lets the daemon restart without killing running containers.
WHY IT EXISTS Container daemons like containerd need to manage hundreds of containers but shouldn't be directly tied to their lifecycles. If the daemon crashed or needed an upgrade, all running containers would die with it. This creates a single point of failure for the entire system.
THE MENTAL MODEL Think of the shim as a dedicated babysitter for each container. The manager (containerd) hires the babysitter and gives it instructions. The manager can then leave, run errands (like restarting), and come back later, trusting the babysitter to keep the child (the container) alive and well. The shim's only job is to parent that one container process, decoupling it from the manager.
HOW IT WORKS When you ask containerd to run a container, it doesn't directly start it. Instead, containerd prepares the container's filesystem and configuration. It then launches a shim process, for example, containerd-shim-runc-v2. This shim then uses a low-level OCI runtime like runc to create and run the container process. The runc process typically exits after starting the container, but the shim process persists as the container's parent, forwarding I/O and exit codes back to containerd over a well-defined API.
WHEN TO USE IT This pattern is fundamental to modern container engines like containerd and CRI-O, which are the backbone of Kubernetes. You don't "choose" to use a shim; it's an integral part of how these systems achieve robustness and so-called "daemon-less" containers. It's the default for any production-grade container orchestration.
WHEN NOT TO USE IT For simple, local development or scripting where you just want to run a single container and don't care about daemon restarts, you might interact with a lower-level tool like runc directly. However, in any managed or production environment, the shim model is non-negotiable for stability and high availability.
ONE CANONICAL EXAMPLE On a Kubernetes node, kubelet tells containerd to start a pod's container. containerd launches a containerd-shim-runc-v2 process for that container. This shim process then calls runc to create the container. If you run ps aux on a worker node, you'll see these shim processes—one for each running container—persisting even if you restart the main containerd service.
Read the original → github.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.