A container is a host process wrapped in namespaces, cgroups and a filtered syscall surface, not a machine: what that shares with the host kernel, what it costs, and where the boundary is weaker.
The problem
A team moves a service from VMs to containers and expects the same things to hold: `free -m` shows the 512 MB it was given, `nproc` shows its CPU quota, a kernel module can be loaded, and a compromised process cannot reach the host. None of that is true. A container is a process on the host kernel with a restricted view of it, so resource numbers inside are the host's, the kernel is shared with every neighbour, and the isolation depends on kernel features and filters rather than on a hypervisor.
How it works
- A container is a normal process tree on the host. `docker top` shows its processes with host PIDs, `ps` on the host lists them, and `uname -r` inside returns the host kernel release (verified: identical output inside and outside). There is no guest kernel, no virtual hardware and no boot sequence.
- What the process can see is set by namespaces. The default runc spec for a Docker container creates new mount, network, UTS, PID and IPC namespaces, plus a time namespace on Engine 29.5 and later (checked on 29.8 in `config.json` and in `/proc/<pid>/ns/*`); the user and cgroup namespaces are not unshared, so root in the container is UID 0 on the host unless you enable user-namespace remapping.
- What the process can use is set by cgroups. `--memory 64m` writes 67108864 to `memory.limit_in_bytes` (cgroup v1, verified) or `memory.max` (cgroup v2). The limit is enforced by the kernel, but `/proc/meminfo` and `/proc/cpuinfo` are not namespaced by cgroups, so `free -m` and `nproc` inside a limited container still print the host's totals (verified: 16 GB and 4 CPUs under `--memory 64m --cpus 0.5`). Runtimes and libraries that size themselves from those files over-allocate.
- What the process may ask the kernel to do is filtered. Docker drops all but 14 capabilities by default (CapEff `00000000a80425fb` in the verified run), applies a default seccomp profile and an AppArmor or SELinux profile where the host has one. `unshare -u`, `dmesg` and `date -s` fail with `Operation not permitted` in a default container (verified), but every permitted syscall still enters the shared kernel directly.
- Startup is process creation, not boot: `docker run --rm busybox:1.37 true` finished in about 0.35 s here including create, network setup and teardown. An idle `sleep` loop showed 976 KiB in `docker stats`. A VM pays for a guest kernel, init, and reserved RAM before the application starts.
- The boundary is weaker than a hypervisor. A kernel bug, a leaked capability, `--privileged`, a mounted `/var/run/docker.sock`, or `--pid=host` (which showed the host's PID 1 and kernel threads in the verified run) gives the container reach into the host. For hostile multi-tenant code, sandboxed runtimes such as gVisor or Kata Containers add a second boundary at the cost of compatibility and speed.
- The kernel is a dependency of the image. Image architecture must match the CPU (an `amd64` image on `arm64` needs emulation and is typically much slower), and features such as cgroup v1 versus v2, overlayfs, or specific syscalls come from the host, so the same image can behave differently across hosts.
- State is separate from the instance. The writable layer disappears with `docker rm`, which suits disposable instances, and anything that must survive goes to a volume. A VM keeps its disk across reboots by default, which is why snapshots and in-place patching are normal there and rare for containers.
Examples
Shared kernel, unchanged /proc totals, limit in the cgroup, and the container process on the host.
# Same kernel inside and outside
uname -r
docker run --rm busybox:1.37 uname -r
# /proc is not cgroup-aware: limits do not change what free and nproc print
docker run --rm --memory 64m --cpus 0.5 busybox:1.37 sh -c 'free -m | head -2; nproc'
# The limit itself lives in the cgroup (cgroup v1 path; cgroup v2 uses /sys/fs/cgroup/memory.max)
docker run --rm --memory 64m busybox:1.37 cat /sys/fs/cgroup/memory/memory.limit_in_bytes
# The container's process is visible on the host
docker run -d --name demo-vm busybox:1.37 sleep 300
ps -eo pid,ppid,cmd | grep '[s]leep 300'
docker top demo-vm
docker rm -f demo-vmFiltered syscalls and capabilities, and which namespaces are actually separate by default.
# Default containers cannot do kernel-level things: capability and seccomp filters
docker run --rm busybox:1.37 unshare -u true; echo "exit=$?"
docker run --rm busybox:1.37 dmesg 2>&1 | head -1
docker run --rm busybox:1.37 date -s "2030-01-01" 2>&1 | grep -i permitted
# Namespaces: the container's mnt/pid/net/uts/ipc/time differ from the host's (time only on Engine 29.5+), user and cgroup do not
for n in cgroup user mnt pid net uts ipc time; do
echo "host $n $(readlink /proc/self/ns/$n)"
done
docker run --rm busybox:1.37 sh -c 'for n in cgroup user mnt pid net uts ipc time; do echo "ctr $n $(readlink /proc/self/ns/$n)"; done'In practice
- Docker Engine, containerd — Create the namespaces and cgroups and hand the process to runc; the container is a child of a shim, not of a hypervisor.
- Kubernetes — Pods are groups of containers sharing a network namespace; node-level kernel upgrades affect every container on the node at once.
- gVisor, Kata Containers, Firecracker — Add a user-space kernel or a micro-VM under an OCI-compatible runtime when the shared-kernel boundary is not enough.
- AWS Lambda, Fly.io — Run customer code in micro-VMs (Firecracker) even though the packaging format is a container image, because the isolation requirement is VM-grade.
- Podman — Same kernel primitives without a central daemon, commonly run rootless.
Trade-offs
Pros
- Starts in well under a second and costs almost no memory beyond the application's own
- One host kernel means high density: hundreds of idle containers fit where a few VMs would
- The image is the deployment unit: the same bytes run on a laptop, CI and production
- Resource limits and process visibility are plain kernel interfaces that standard tools (`ps`, `perf`, `strace`) can use from the host
Cons
- A kernel vulnerability or misconfiguration affects every container on the host
- Containers cannot run a different kernel or kernel modules, and depend on the host's cgroup and filesystem features
- `/proc` and `/sys` values inside the container do not reflect its limits, which misleads runtimes that auto-size
- Weaker isolation makes hostile multi-tenancy a poor fit without an additional sandbox layer