Sub topic 9
Runtimes and the OCI standards
This chapter assumes you know what a process is, what a kernel does, and how namespaces, cgroups, and image layers work. Those three pieces are only kernel features and files. A container runtime combines them into a running container.
What a container runtime does
A container runtime is a program that takes a packaged image and starts it as an isolated process. It does the following steps:
- Unpack the image layers into a root filesystem.
- Create new namespaces for the process.
- Place the process in a cgroup with its resource limits.
- Start the configured command inside that environment.
The kernel does the isolating. The runtime only asks the kernel to do it.
Two levels of runtime
The word "runtime" covers two different jobs, and mixing them up is a common source of confusion.
| Level | Job | Examples |
|---|---|---|
| High-level runtime | Pulls images, stores layers, manages container lifecycle, exposes an API | containerd, CRI-O |
| Low-level runtime | Creates the namespaces and cgroups and starts the process | runc, crun |
Docker is a tool built on top of these. When you type docker run, the Docker CLI talks to the Docker daemon. The daemon uses containerd, and containerd calls runc to start the process. Kubernetes skips the Docker layer and talks to containerd or CRI-O directly.
The OCI standards
The Open Container Initiative (OCI) is an industry group that publishes open specifications so that tools from different vendors work together. Three specifications matter:
- The Image Specification defines how an image is stored: a manifest, a configuration, and an ordered list of layers, each identified by a digest.
- The Runtime Specification defines what a runtime receives: a root filesystem and a
config.jsonfile describing namespaces, cgroup limits, mounts, and the command to run. - The Distribution Specification defines the HTTP API that registries use to push and pull images.
Because of these standards, an image built with Docker can run under Podman or containerd. Any compliant registry can store it.
Seeing the OCI pieces
You can look at the layer list that the Image Specification defines. This command prints the layer digests of the alpine image:
docker image inspect --format '{{json .RootFS.Layers}}' alpineEach entry is a content digest such as sha256:.... Two images that share a layer share the same digest, so the layer is stored once.
The runtime side is visible too. runc can generate a default runtime configuration:
runc spec
head -n 20 config.jsonThe generated config.json lists the process arguments, the root filesystem path, and the namespaces to create. This is the file that connects the Runtime Specification to the kernel features from earlier chapters.
Why the split matters
Separating the image format, the runtime interface, and the registry API gives you three practical benefits:
- You can swap the low-level runtime without rebuilding images. Replacing runc with a sandboxed runtime is a configuration change. Later chapters on hybrid approaches rely on this.
- Build tools and orchestrators do not depend on one vendor.
- Images are portable between machines that run any compliant runtime.
Exercise
You run docker run alpine echo hi. Which component creates the namespaces and cgroups for the process, and which component pulled and unpacked the image?
Show answer
The low-level runtime, runc, creates the namespaces and cgroups and starts the process. The high-level runtime, containerd (called by the Docker daemon), pulled the image and unpacked its layers.
Exercise
Why can an image built with Docker be run by Podman or CRI-O without changes?
Show answer
All three follow the OCI Image Specification and Runtime Specification, so they read the same image format and give the low-level runtime the same kind of configuration.