Containers are often described as "lightweight virtual machines." They are not. A container is a process tree on the host kernel, given a private view of the system through namespaces and limited by cgroups. There is no guest kernel, no virtual hardware, and no hypervisor in the path. That is why a container starts in milliseconds and why its isolation boundary is thinner.
The useful way to read this chapter is as a spectrum. At one end, a full VM gives you a hardware-enforced boundary and pays for it in memory and boot time. At the other, a container gives you density and developer ergonomics but shares the kernel. MicroVMs and user-space kernels sit in between, trying to buy back isolation without giving up the operational model of containers.
From chroot to Docker
Process isolation is older than Linux. chroot appeared in Version 7 Unix
in 1979 and changed a process's view of the filesystem root. FreeBSD jails (2000) added
process and network isolation. Solaris Zones (2004) packaged a full application
environment with resource controls. None of these were virtual machines, but all of
them explored the same question: how little of the host does a workload need to see?
Linux assembled the modern primitives piece by piece:
- Namespaces — mount (2002), UTS/IPC/PID (2006), network (2008), user (2013), cgroup and time later. Each namespace hides or virtualizes one global resource.
- cgroups — control groups, merged into the kernel in 2008, limit CPU, memory, I/O and process counts. cgroups v2 unified the hierarchy.
- Capabilities, seccomp and LSMs — drop privileged operations, filter syscalls, and apply mandatory access control (SELinux, AppArmor).
LXC (2008) exposed these primitives as system containers. Docker (2013) added a developer-friendly image format, a registry and a CLI, and the ecosystem exploded. The Open Container Initiative (2015) standardized the image and runtime formats; Kubernetes (2014) standardized orchestration. The container became the unit of application packaging, even when the underlying infrastructure was still VMs.
What is actually inside a container
A running container is a normal Linux process with a different set of namespaces, a cgroup, a restricted capability set and a root filesystem assembled from image layers. You can see its namespaces from the host:
$ docker run --rm -d --name demo \
--memory=512m --cpus=1 --pids-limit=256 \
--read-only --cap-drop=ALL nginx:alpine
$ PID=$(docker inspect -f '{{.State.Pid}}' demo)
$ sudo ls -l /proc/$PID/ns
lrwxrwxrwx ... cgroup -> 'cgroup:[4026531835]'
lrwxrwxrwx ... ipc -> 'ipc:[4026532508]'
lrwxrwxrwx ... mnt -> 'mnt:[4026532506]'
lrwxrwxrwx ... net -> 'net:[4026532509]'
lrwxrwxrwx ... pid -> 'pid:[4026532507]'
lrwxrwxrwx ... user -> 'user:[4026531837]'
lrwxrwxrwx ... uts -> 'uts:[4026532505]'
$ cat /proc/$PID/cgroup
0::/system.slice/docker-3f2a....scope
$ sudo nsenter -t $PID -n ip addr
1: lo: <LOOPBACK,UP> mtu 65536
2: eth0@if7: <BROADCAST,MULTICAST,UP> mtu 1500
The host kernel is the same kernel in every container. A kernel vulnerability, a
misconfigured capability, or a device exposed to the container can become a host
compromise. This is not a theoretical concern: container escapes via privileged
containers, mounted Docker sockets, kernel bugs and /proc abuses are a
recurring class of incident.
The isolation trade-off
| Property | Container | Full VM |
|---|---|---|
| Kernel | Shared with host | Own guest kernel |
| Boot / start | Milliseconds | Seconds to a minute |
| Memory overhead | Megabytes | Hundreds of MB to GB |
| Density | Hundreds per host | Tens per host |
| Isolation boundary | Namespaces, cgroups, seccomp, LSM | Hypervisor + hardware |
| Attack surface | Host kernel syscall interface | Hypervisor + device model |
| Live migration | Not natively (checkpoint/restore is emerging) | Mature |
| Best fit | Trusted multi-tenant apps, CI, packaging | Untrusted tenants, heterogeneous OSes |
The trade-off is not "containers are insecure." It is that the boundary is different. If you control the workloads and patch the kernel, containers are a reasonable boundary. If you run arbitrary code from customers, agents or the internet, a shared kernel is a much larger risk.
MicroVMs: the best of both, with a smaller device model
In 2018 AWS open-sourced Firecracker, a virtual machine monitor written in Rust and built on KVM. It was designed for Lambda and Fargate, where the provider needed VM-level isolation for untrusted function code but could not afford a full QEMU boot per invocation. Firecracker boots a minimal guest in as little as 125 ms, with less than 5 MiB of memory overhead per microVM.
The trick is subtraction. Firecracker exposes only a handful of devices: virtio-net, virtio-block, a serial console, a programmable interval timer and a minimal keyboard controller for resets. No VGA, no USB, no PCIe topology, no legacy chipset. A smaller device model means a smaller attack surface and less initialization work. A jailer process wraps each microVM with namespaces, cgroups and seccomp.
Two other projects occupy nearby points. Kata Containers (2017) runs each Kubernetes pod inside a lightweight VM while keeping the OCI container interface, so the orchestrator does not need to know. gVisor (Google, 2018) implements a user-space kernel that intercepts syscalls from the container, reducing the host kernel surface without requiring hardware virtualization.
Starting a Firecracker microVM
Firecracker is controlled through a REST API over a Unix socket. A configuration file can define the boot source, root drive, machine size and network interface:
{
"boot-source": {
"kernel_image_path": "vmlinux",
"boot_args": "console=ttyS0 reboot=k panic=1 pci=off"
},
"drives": [{
"drive_id": "rootfs",
"path_on_host": "rootfs.ext4",
"is_root_device": true,
"is_read_only": false
}],
"machine-config": {
"vcpu_count": 2,
"mem_size_mib": 512,
"smt": false
},
"network-interfaces": [{
"iface_id": "eth0",
"guest_mac": "AA:FC:00:00:00:01",
"host_dev_name": "tap0"
}]
}
$ firecracker --api-sock /tmp/fc.sock --config-file vmconfig.json
# in another shell, after the API socket appears:
$ curl --unix-socket /tmp/fc.sock -X PUT http://localhost/actions \
-H 'Content-Type: application/json' \
-d '{"action_type": "InstanceStart"}'
HTTP/1.1 204 No Content
Kubernetes and the runtime class
Kubernetes abstracts the container runtime behind the Container Runtime Interface.
RuntimeClass lets a pod request a stronger sandbox without changing
the application manifest: runtimeClassName: kata-firecracker or
gvisor. The pod still looks like a container to the developer; underneath,
the runtime may boot a microVM.
This is the pragmatic outcome of the last decade. Containers won the developer interface — images, registries, Kubernetes, CI pipelines. VMs won the security boundary for untrusted workloads. MicroVMs and user-space kernels combine the two, and the orchestrator hides the difference.
"Containers are more secure because they are smaller" is backwards. Smaller images
reduce the software supply chain surface, but the isolation boundary is the host
kernel. A container with --privileged or a mounted Docker socket is
effectively root on the host.