Mental model
Containers are NOT virtual machines. A container is a standard Linux process isolated by Namespaces (what the process can see) and bounded by Control Groups (cgroups v2) (how much resources the process can use).
Theory
- Linux Namespaces: Virtualize system resources.
pid: Process tree isolation (container process sees itself as PID 1).net: Isolated network devices, IP routing tables, and port bindings.mnt: Isolated file system mount points (chroot/pivot_root).user: Maps root user inside container (UID 0) to unprivileged UID on host.
- cgroups v2 (Unified Hierarchy): Controls CPU (
cpu.max), RAM (memory.max), Disk I/O (io.max), and PIDs (pids.max).
Alternatives and trade-offs
- Virtual Machines (KVM / QEMU): Full guest OS hypervisor isolation; heavy RAM overhead and slow startup times.
- Linux Containers (cgroups v2 + Namespaces): Lightweight process isolation, native host speed, instant startup; shares the single host kernel.
Failure modes and misconceptions
- Host Memory Exhaustion via Uncapped Containers: Spawning containers without explicit
memory.maxlimits allows a single rogue container process to consume all host RAM, triggering global host OOM crashes. - Running Containers as Real Host Root: Running container processes without
usernamespace mapping means a container breakout grants full root access to the host host OS.
Decision scenario
Configure cgroups v2 memory.max and cpu.max controllers for production container deployments to prevent runaway processes from starving host resources.
Learning outcomes
- Explain how Linux Namespaces isolate PIDs, networks, and file mounts.
- Restrict container CPU, RAM, and PID allocations using
cgroups v2. - Secure host operating systems by enabling
usernamespace mapping.
Trade-offs
cgroups v2 and namespaces deliver near-zero overhead container virtualization, but share the single host kernel across all isolated process environments.