A Container Shares the Host Kernel, a Virtual Machine Runs Its Own

In progress Docker Linux

A container packages an application with its dependencies so it runs the same everywhere, but it is not a small virtual machine. It's an ordinary Linux process isolated by kernel features and sharing the host's kernel. That's why containers start in milliseconds and stay light, and also why their isolation is weaker than a VM's.

How the Isolation Works

Kernel feature Isolates
Namespaces what the process sees: its own process tree, network interfaces, mount points, hostname, users
cgroups what it may use: CPU, memory, I/O limits
Layered filesystem (OverlayFS) the image's read-only layers plus a thin writable layer per container

The image carries the application, libraries and a userland (a Debian or Alpine base), never a kernel.

Containers and VMs Compared

Container Virtual machine
Kernel the host's, shared its own, on a hypervisor
Startup milliseconds seconds to minutes
Size megabytes gigabytes
Isolation boundary the kernel: one kernel bug can affect every container the hypervisor: much smaller attack surface
Runs another OS no: Linux containers need a Linux kernel (Docker Desktop runs a hidden VM on macOS and Windows) yes

References

Review cards

Flashcard What do namespaces control for a container process?

What it can see: its own process tree, network interfaces, mount points, hostname and users. Limits on what it may use (CPU, memory, I/O) come from cgroups.

Flashcard Why does a container start in milliseconds when a VM takes seconds or minutes?

A container is an ordinary process on the host's already running kernel; a VM must boot its own kernel and operating system on a hypervisor.

Quiz Why is a container's isolation weaker than a virtual machine's?
  • Containers share the host kernel, so one kernel bug can affect them all
  • Virtual machines have no attack surface at all
  • Containers run their own kernel, which is less tested
  • Containers cannot use cgroups to limit resources

A VM's boundary is the hypervisor, a much smaller attack surface than the shared kernel every container talks to.