Week 2 - The OCI Runtime Spec, runc, and crun¶
2.1 Conceptual Core¶
- A runtime bundle = a directory containing
config.json(the runtime spec) +rootfs/(the filesystem to chroot/pivot_root into). runc create <id>readsconfig.json, sets up namespaces, cgroups, mounts, seccomp, capabilities, then waits.runc start <id>runs the configured command.runc state <id>shows status.runc kill <id> SIGTERMsignals.runc delete <id>cleans up.- Two production runtimes both implementing the OCI runtime spec:
runc(Go, the reference; what Docker / containerd use by default).crun(C, faster startup, lower memory, default in Podman on RHEL/Fedora).youki(Rust, gaining ground; primary Rust implementation).
2.2 Mechanical Detail¶
config.jsonschema (runtime-spec/config.md). Major sections:- `process - args, env, user, capabilities, rlimits.
root - path to rootfs,readonly` flag.mounts - list of`.linux.namespaces,linux.uidMappings, `linux.gidMappings - isolation.- `linux.resources - cgroups settings.
- `linux.seccomp - full seccomp filter.
linux.maskedPaths, `linux.readonlyPaths - host-leakage hardening.- `hooks - pre/post container lifecycle.
2.3 Lab-"Run a Container Without Docker"¶
- Generate a default config:
runc specproducesconfig.json. - Build a rootfs:
mkdir rootfs && skopeo copy docker://alpine:3.19 oci:./alpine && umoci unpack --image ./alpine:3.19 ./bundle(umoci gives you both rootfs + config in one step). Or do it manually. - Run:
sudo runc run mycontainer. You're inside the container. - Modify the config to: drop all capabilities except
CAP_NET_BIND_SERVICE, set a memory limit of 64M, mask/proc/sys. Re-run; verify withcat /proc/self/status | grep Capand pressure tests. - Repeat with
crun. Time the startup difference (time runc runvstime crun run)-crunis typically 2–5× faster.
2.4 Hardening Drill¶
- Read the default seccomp profile in
runc'slibcontainer/seccomp/seccomp_default.go(the equivalent profile is shipped with Docker asdefault.json). Note which syscalls it blocks. Review the spec'slinux.seccompschema and write a tighter custom profile for a specific service.
2.5 Production Readiness Slice¶
- Add an automated CI step that lints any custom
config.jsonagainst the OCI spec schema. Userunc spec --rootlessand study the differences vs the privileged config-this is the foundation for Month 3's rootless work.