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.
Namespace
Isolates
Introduced
mnt
Filesystem mount points
Linux 2.4.19 (2002)
pid
Process IDs (the container sees PID 1)
Linux 2.6.24 (2008)
net
Network interfaces, routing tables, sockets
Linux 2.6.29 (2009)
ipc
SysV IPC, POSIX message queues
Linux 2.6.19 (2006)
uts
Hostname, domain name
Linux 2.6.19 (2006)
user
UID/GID mapping; root inside ≠ root outside
Linux 3.8 (2013)
cgroup
Cgroup root view
Linux 4.6 (2016)
time
System clock view
Linux 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:
Spec
Latest
Defines
Reference impl
Image Spec
v1.1 (2024)
Manifest, config, layer formats, annotations.
Docker / containerd image handling.
Runtime Spec
v1.2 (2024)
The config.json bundle a runtime consumes to start a container.
runc.
Distribution Spec
v1.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
Runtime
Layer
Notable
Docker Engine
High-level (uses containerd + runc)
The original developer UX; docker CLI + dockerd.
containerd
High-level (CNCF Graduated)
Used by Docker, Kubernetes (default since 1.24), AWS Fargate, EKS, GKE, AKS.
CRI-O
High-level (CNCF Graduated)
Minimal CRI runtime for K8s; OpenShift default.
Podman
High-level, daemonless
Rootless by default; podman generate kube; Quadlet for systemd integration.
Mirantis Container Runtime
Commercial Docker successor
FIPS, Windows containers, enterprise support.
runc
Low-level (OCI runtime)
The reference implementation; Go binary that calls clone() + setns().
crun
Low-level, C
Faster startup, lower memory; default on Fedora/RHEL.
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 — builderFROM 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
EXPOSE8080HEALTHCHECK CMD ["/app", "healthcheck"]
ENTRYPOINT ["/app"]
Base image
Size
Includes
Use
scratch
0 B
Nothing
Statically linked Go / Rust binaries.
distroless/static
~2 MB
ca-certs, tzdata, libc6-compat-free
Static binaries needing certs/tz.
distroless/base
~20 MB
glibc, ca-certs
Dynamic binaries (Rust, C).
chainguard/static, Wolfi
~5 MB
Hardened, daily-rebuilt, signed
Near-zero-CVE production.
alpine
~7 MB
musl, BusyBox shell
Quick iteration; watch glibc compat.
ubuntu:24.04
~80 MB
Full glibc + apt
Compat 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
Registry
Vendor
Strengths
Docker Hub
Docker Inc.
Largest public catalogue; rate limits on anon pulls.
GitHub Container Registry (GHCR)
GitHub
Co-located with code; PAT & OIDC auth; free for public.
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.
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
Mechanism
Project
What it proves
Cosign
Sigstore (OpenSSF, Linux Foundation)
An identity (keyless via OIDC) signed this image digest.
Rekor
Sigstore
Public transparency log of every signature.
Fulcio
Sigstore
Short-lived cert authority bound to OIDC identity.
Notation
CNCF (Notary v2)
X.509-rooted signing; preferred by enterprises with existing PKI.
in-toto attestations
CNCF Graduated (in-toto)
Signed JSON statements about the artefact (built by, test results, SBOM).
SLSA build provenance
OpenSSF
Levels 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 control
Where to set
Effect
securityContext.runAsNonRoot: true
K8s pod spec
kubelet refuses to start if the image runs as root.
allowPrivilegeEscalation: false
K8s container spec
Disables setuid bits at exec time.
capabilities.drop: ["ALL"]
K8s container spec
Removes all Linux caps; add back individually.
seccompProfile.type: RuntimeDefault
K8s pod or container
Applies the curated default syscall filter.
PSA (Pod Security Admission) restricted
K8s namespace label
Enforces 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.