LOOP · The DevOps Codex
Ch 08 · Containers & Runtimes
Chapter 08 · The Package Unit of the Cloud

Containers & Container Runtimes — a process tree in a kernel-enforced box

A container is not a tiny virtual machine. It is one or more Linux processes whose view of the operating system has been narrowed by namespaces, whose resource consumption has been capped by cgroups, and whose filesystem is a layered, content-addressed image. The OCI specifications turned that pattern into a portable contract — image, runtime, distribution — that every modern orchestrator now consumes.

8.1 · What a container actually is

Definition. A container is one or more processes running on a host kernel whose system-call view has been restricted by Linux namespaces, whose CPU/memory/IO usage is bounded by cgroups, and whose root filesystem is supplied by a layered, copy-on-write image. There is no guest kernel and no hypervisor; the isolation is enforced entirely by the host kernel.

NamespaceIsolatesIntroduced
mntFilesystem mount pointsLinux 2.4.19 (2002)
pidProcess IDs (the container sees PID 1)Linux 2.6.24 (2008)
netNetwork interfaces, routing tables, socketsLinux 2.6.29 (2009)
ipcSysV IPC, POSIX message queuesLinux 2.6.19 (2006)
utsHostname, domain nameLinux 2.6.19 (2006)
userUID/GID mapping; root inside ≠ root outsideLinux 3.8 (2013)
cgroupCgroup root viewLinux 4.6 (2016)
timeSystem clock viewLinux 5.6 (2020)
  • cgroups v2 (default on modern distros since 2021) — unified hierarchy controlling cpu, memory, io, pids, hugetlb.
  • Union filesystem — overlay2 layers the image RO layers + a thin RW upper; tiny pod, large illusion of full disk.
  • The process is the workload. No init, no SSH, no cron — when PID 1 exits, the container is gone.
The mental model: a container is your binary, the libraries it dynamically links, a few environment variables, and a kernel that politely pretends nothing else exists.

8.2 · OCI — the specs that made containers portable

The Open Container Initiative was founded in 2015 (Linux Foundation) to standardise what Docker had popularised. There are three specs:

SpecLatestDefinesReference impl
Image Specv1.1 (2024)Manifest, config, layer formats, annotations.Docker / containerd image handling.
Runtime Specv1.2 (2024)The config.json bundle a runtime consumes to start a container.runc.
Distribution Specv1.1 (2023)HTTP API for push/pull/manifest/tags from a registry.Docker Registry v2.

The 2023 Reference Types and OCI Artefact Manifest extensions let registries store any content-addressed payload — Helm charts, WASM modules, ML models, SBOMs, signatures — using the same protocol. Helm 3, ORAS, Cosign and Sigstore all rely on this.

8.3 · Container runtimes

RuntimeLayerNotable
Docker EngineHigh-level (uses containerd + runc)The original developer UX; docker CLI + dockerd.
containerdHigh-level (CNCF Graduated)Used by Docker, Kubernetes (default since 1.24), AWS Fargate, EKS, GKE, AKS.
CRI-OHigh-level (CNCF Graduated)Minimal CRI runtime for K8s; OpenShift default.
PodmanHigh-level, daemonlessRootless by default; podman generate kube; Quadlet for systemd integration.
Mirantis Container RuntimeCommercial Docker successorFIPS, Windows containers, enterprise support.
runcLow-level (OCI runtime)The reference implementation; Go binary that calls clone() + setns().
crunLow-level, CFaster startup, lower memory; default on Fedora/RHEL.
youkiLow-level, RustMemory-safe alternative; experimental.
gVisorSandbox (Google)Userspace kernel intercepts syscalls; stronger isolation, perf cost.
Kata ContainersmicroVM (OpenStack Foundation)One lightweight VM per pod; near-VM isolation, container UX.
FirecrackermicroVM (AWS)Powers Lambda & Fargate; ~125 ms boot.
kubelet CRI · containerd runc / crun Linux kernel orchestrator high-level runtime low-level (OCI) namespaces + cgroups

8.4 · Image-build tooling

ToolApproachBest for
Docker BuildKitDefault Docker build engine since 23.0 (2023); parallel stages, cache mounts, secret mounts.Developer machines, general-purpose.
buildahDaemonless, scriptable, from Red Hat.Rootless CI, Podman ecosystems.
KanikoBuilds inside a container without a Docker daemon.Untrusted CI runners on Kubernetes.
imgDaemonless wrapper over BuildKit.Lightweight CI builds.
Cloud Native BuildpacksPaketo, Heroku Buildpacks; no Dockerfile, detection-based.Polyglot platforms wanting a paved path.
nixpacksRailway's auto-detect builder; OCI output.PaaS-like ergonomics.
koGo-only; builds + pushes a scratch-based image in one command, no Dockerfile.Pure Go services.
JibMaven/Gradle plugin; layers JAR/classes/deps separately, no daemon.Java microservices.
apko + melangeChainguard tools; declarative apk-based, fully reproducible.Wolfi / hardened bases.

8.5 · The multi-stage Dockerfile pattern

A multi-stage Dockerfile compiles in a fat builder stage and copies only the artefact into a slim runtime stage. The final image contains nothing but what is needed to run.

# syntax=docker/dockerfile:1.7
## Stage 1 — builder
FROM golang:1.22-alpine@sha256:8e96e6cff... AS builder
WORKDIR /src
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/.cache/go-build \
    --mount=type=cache,target=/go/pkg/mod \
    go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux \
    go build -trimpath -ldflags="-s -w" -o /out/app ./cmd/app

## Stage 2 — runtime (distroless)
FROM gcr.io/distroless/static-debian12:nonroot@sha256:a9f88e0...
COPY --from=builder /out/app /app
USER nonroot:nonroot
EXPOSE 8080
HEALTHCHECK CMD ["/app", "healthcheck"]
ENTRYPOINT ["/app"]
Base imageSizeIncludesUse
scratch0 BNothingStatically linked Go / Rust binaries.
distroless/static~2 MBca-certs, tzdata, libc6-compat-freeStatic binaries needing certs/tz.
distroless/base~20 MBglibc, ca-certsDynamic binaries (Rust, C).
chainguard/static, Wolfi~5 MBHardened, daily-rebuilt, signedNear-zero-CVE production.
alpine~7 MBmusl, BusyBox shellQuick iteration; watch glibc compat.
ubuntu:24.04~80 MBFull glibc + aptCompat with legacy binaries.

8.6 · Image hygiene

  • Pin base by digest (image@sha256:...), not by tag — tags are mutable and reproducibility-hostile.
  • .dockerignore first — keep node_modules, .git, *.env, test fixtures out of the context.
  • Non-root user — USER 65532 or distroless nonroot; combine with K8s runAsNonRoot: true.
  • Healthcheck for orchestrator liveness signals.
  • Minimise layers — combine related RUN steps; clean apt lists in the same layer; avoid trailing big install layers.
  • No secrets at build. Use BuildKit --mount=type=secret; never ENV API_KEY=....
  • SOURCE_DATE_EPOCH + --reproducible flags for deterministic layer hashes.

8.7 · Registries

RegistryVendorStrengths
Docker HubDocker Inc.Largest public catalogue; rate limits on anon pulls.
GitHub Container Registry (GHCR)GitHubCo-located with code; PAT & OIDC auth; free for public.
Amazon ECRAWSIAM-native, pull-through cache, ECR Public, immutable tags.
Google Artifact RegistryGCPSuccessor to GCR; multi-format (Docker, Maven, npm, OCI).
Azure Container RegistryAzureGeo-replication, Tasks (build in registry), Connected Registry for edge.
Quay.ioRed HatClair scanning, robot accounts, GitOps workflows.
HarborCNCF Graduated (self-hosted)Replication, Trivy scanning, Cosign signing, RBAC.
JFrog ArtifactoryJFrogUniversal repository (Docker + 30 other types).
CloudsmithCloudsmithHosted, multi-format, fine-grained access.
ZotCNCF SandboxOCI-native, vulnerability scanning, sync; lightweight self-host.

8.8 · Image scanning

Definition. Image scanning enumerates the software bill of materials (SBOM) of an image and matches each component against vulnerability databases (NVD, GitHub Advisory DB, OSV, distro feeds).

  • Trivy (Aqua Security, OSS) — de-facto standard; OS packages, language deps, IaC, secrets, misconfig.
  • Grype + Syft (Anchore) — Syft for SBOM, Grype for CVE; great CI ergonomics.
  • Snyk Container — commercial, fix advice, base-image upgrade suggestions.
  • Clair — original Quay scanner; static analysis.
  • Anchore Enterprise — policy engine + compliance reporting.
  • Wiz, Prisma Cloud, Aqua, Sysdig — runtime + build CSPM/CWPP suites.
  • Trivy Operator — Kubernetes admission & continuous in-cluster scanning.
Distroless & Wolfi pay back in CVE count. A Debian-based image typically ships hundreds of packages you do not use. Each is a CVE surface. Switching to distroless drops the count to a handful; Wolfi/Chainguard rebuilds nightly so zero-CVE is achievable for many services.

8.9 · Image signing & provenance

MechanismProjectWhat it proves
CosignSigstore (OpenSSF, Linux Foundation)An identity (keyless via OIDC) signed this image digest.
RekorSigstorePublic transparency log of every signature.
FulcioSigstoreShort-lived cert authority bound to OIDC identity.
NotationCNCF (Notary v2)X.509-rooted signing; preferred by enterprises with existing PKI.
in-toto attestationsCNCF Graduated (in-toto)Signed JSON statements about the artefact (built by, test results, SBOM).
SLSA build provenanceOpenSSFLevels 1–4 of build-system integrity; Level 3 = hermetic, signed.
# Sign and verify with cosign (keyless)
cosign sign ghcr.io/acme/api@sha256:abcd...
cosign verify ghcr.io/acme/api@sha256:abcd... \
  --certificate-identity=https://github.com/acme/api/.github/workflows/release.yml@refs/heads/main \
  --certificate-oidc-issuer=https://token.actions.githubusercontent.com

8.10 · Multi-arch images

Definition. A manifest list (a.k.a. image index, OCI Spec) is a top-level manifest that points to per-architecture image manifests. Clients pull the variant matching their host.

  • docker buildx — --platform linux/amd64,linux/arm64 builds and pushes a manifest list in one go (BuildKit + QEMU emulation, or native multi-node).
  • arm64 cost wins. AWS Graviton, Oracle Ampere, GitHub arm64 runners (GA 2024) typically run 20–40% cheaper per request.
  • Less common but supported: linux/ppc64le, linux/s390x (IBM mainframe), linux/riscv64 (Wolfi 2024+), windows/amd64.
  • Cross-build hazards — QEMU emulation is slow; prefer native runners per arch and merge manifest lists with docker buildx imagetools create.

8.11 · Container security defaults

  • seccomp — syscall filter. Use the runtime RuntimeDefault profile (denies ~60 syscalls); craft per-app profiles for hardening.
  • AppArmor / SELinux — mandatory access control. RuntimeDefault in K8s; :Z/:z labels on Podman bind mounts.
  • Capabilities — drop all by default, add only what is needed (NET_BIND_SERVICE for < 1024 ports).
  • Read-only root filesystem — readOnlyRootFilesystem: true; mount specific writable emptyDirs where required.
  • No privileged unless necessary — privileged: true bypasses everything; use specific capabilities or device plugins instead.
  • User namespaces — K8s 1.30 graduated hostUsers: false beta; root inside the pod is mapped to an unprivileged host UID.
  • Rootless containers — Podman, BuildKit, and containerd all support running the whole stack without root on the host.
Hardening controlWhere to setEffect
securityContext.runAsNonRoot: trueK8s pod speckubelet refuses to start if the image runs as root.
allowPrivilegeEscalation: falseK8s container specDisables setuid bits at exec time.
capabilities.drop: ["ALL"]K8s container specRemoves all Linux caps; add back individually.
seccompProfile.type: RuntimeDefaultK8s pod or containerApplies the curated default syscall filter.
PSA (Pod Security Admission) restrictedK8s namespace labelEnforces baseline + extra hardening on all pods.
Cross-references
  • Ch 03 — build systems that produce these images.
  • Ch 04 — pipelines that scan, sign, and push images.
  • Ch 07 — GitOps controllers consuming OCI artefacts.
  • Ch 09 — Kubernetes, which orchestrates these containers.
  • Ch 16 — DevSecOps: admission policies, signing verification, SLSA levels.

8.12 · Self-check

Q1 · Which Linux primitives provide isolation for containers (as distinct from virtual machines)?
Hypervisor + virtual NIC
Namespaces + cgroups
A second kernel inside the image
Hardware-virtualised page tables only
Q2 · What does the OCI Distribution Spec standardise?
The format of a Dockerfile.
The seccomp profile applied by default.
The HTTP API for registries to push/pull images and manifests.
The TCP port containers listen on.
Q3 · Why are distroless or Wolfi base images preferred for security-sensitive production workloads?
They are faster at startup because they include a shell.
They strip out shells and package managers, drastically reducing CVE surface and post-compromise tooling.
They are required by the OCI Runtime Spec.
They run as root by default, simplifying ops.