Containers 📦

Kubernetes schedules containers; it does not explain them. This section covers the layer underneath: what a container actually is on a Linux host, how an image is put together and shipped, and what runs it.

If you can explain why a container is “just a process”, why a rebuild is sometimes instant and sometimes slow, and what happens between kubectl apply and a running process, Kubernetes becomes much easier to debug.

Reading order

  1. Namespaces and cgroups — A container is a process with a restricted view and a resource budget. Build one by hand.
  2. Images and layers — The OCI image format, content addressing, the layer cache, multi-architecture images.
  3. Dockerfile best practices — Small, fast, reproducible and secure builds.
  4. Registries — How push and pull work, tags versus digests, authentication, signing, mirroring.
  5. Container runtimes — Docker, containerd, runc and the CRI: who does what.
  6. Container networking — veth pairs, bridges, port publishing and how this becomes Kubernetes networking.
  7. WebAssembly — A different sandbox, and where it does and does not replace containers.

The stack at a glance

            docker CLI / nerdctl / kubectl
                        │
        dockerd                      kubelet
            │                           │  CRI (gRPC)
            └────────► containerd ◄─────┘        ← pulls images, manages snapshots and lifecycles
                           │
                    containerd-shim                ← one per container; survives containerd restarts
                           │
                         runc                      ← OCI runtime: sets up namespaces and cgroups, then exec()
                           │
                 your process (PID 1 in its own namespace)
        ──────────────── Linux kernel ────────────────
          namespaces · cgroups · overlayfs · seccomp · capabilities

The Linux building blocks

These live in the Linux section and are worth reading alongside:

MechanismWhat it providesNote
PID namespaceA private process treeProcess namespace
Mount namespaceA private filesystem viewMount namespace
Network namespacePrivate interfaces, routes and portsNetwork namespace
User namespaceRoot inside, unprivileged outsideUser namespace
cgroupsCPU, memory, I/O and PID limitscgroups
OverlayFSLayered copy-on-write filesystemsOverlayFS
CapabilitiesRoot’s power, split into piecesCapabilities
seccompSystem call filteringseccomp
AppArmorMandatory access control profilesAppArmor

Related tools and comparisons: container runtimes on Linux, Podman, systemd-nspawn, hypervisors and emulation versus virtualisation.

Security

Where containers run