A Linux kernel vulnerability makes the news, and the ticket says "patch every service". The team bumps their API's base image to the newest ubuntu:24.04, rebuilds, redeploys and closes the ticket. The next scan of the servers flags the same kernel as before. The kernel was never in the image. Every container on that server runs on the server's own kernel, and the rebuild didn't touch it.
The common misconception
The belief: a container is a lightweight virtual machine. It boots its own small operating system, kernel included, just faster than a "real" VM. So a container built FROM ubuntu runs Ubuntu, kernel and all.
It's easy to see why. Run docker run -it ubuntu:24.04 bash and you land in a shell that looks like a fresh machine: apt works, /etc/os-release says Ubuntu, you're root, there's a hostname, an IP address and a process list that starts at PID 1. Images are named after distributions. And if you use Docker Desktop on Windows, a virtual machine really is involved.
The half-truth: the isolation is real, and on Docker Desktop there is a VM. But it's one VM under all your containers, not one per container, and the container itself is something much simpler.
What actually happens
A container is a process with its own files
Docker's own docs put it plainly: "A container is simply an isolated process with all of the files it needs to run. If you run multiple containers, they all share the same kernel." A VM, by contrast, is "an entire operating system with its own kernel, hardware drivers, programs, and applications." The image supplies the files: libraries, a shell, a package manager. The that runs them is the host's. In our test, /boot was empty in the Ubuntu image and absent in the Alpine one, and neither had /lib/modules.
Here's that on Docker 29.4 with two images we pulled for the test:
Bash · terminal
docker run --rm ubuntu:24.04 grep PRETTY /etc/os-release# PRETTY_NAME="Ubuntu 24.04.5 LTS"docker run --rm alpine:3.22 grep PRETTY /etc/os-release# PRETTY_NAME="Alpine Linux v3.22"docker run --rm ubuntu:24.04 uname -r# 6.6.114.1-microsoft-standard-WSL2docker run --rm alpine:3.22 uname -r# 6.6.114.1-microsoft-standard-WSL2
Two distributions' files, one kernel. This machine runs Docker Desktop on Windows, so that kernel is WSL 2's, which Microsoft describes as running "a Linux kernel inside of a lightweight utility virtual machine (VM)." On a Linux server you'd see the server's own kernel version instead.
Namespaces decide what the process can see
If it's just a process, why does it look like a machine? The Linux man pages explain: a "wraps a global system resource in an abstraction that makes it appear to the processes within the namespace that they have their own isolated instance of the global resource." There are namespaces for process IDs, mount points, network stacks, the hostname and more, and Docker creates a set for every container. Docker's security docs call them "the first and most straightforward form of isolation": processes in a container "cannot see, and even less affect, processes running in another container, or in the host system."
cgroups decide what it can use
The other half is the . Per the same docs, cgroups "implement resource accounting and limiting" and help ensure "that a single container cannot bring the system down by exhausting one of those resources." Both mechanisms belong to the kernel, and you can watch them work:
Inside the container, sleep is PID 1. docker top shows the same process as PID 709103: one process, two views, thanks to the PID namespace. The --memory 64m flag became a cgroup limit of 67108864 bytes, and when tail /dev/zero kept allocating past it, the kernel killed it with exit code 137. In a run without --rm, docker inspect reported OOMKilled as true.
Where VMs do come in
Containers and VMs aren't rivals. Docker's docs note that "you will see containers and VMs used together": a cloud VM running a container runtime can host many containerized apps. Docker Desktop on Windows is the same idea: one Linux VM, one kernel, all your Linux containers on it. Windows containers add a choice. With process isolation they "share the same kernel with the host as well as each other". With Hyper-V isolation, Microsoft says, "each container runs inside of a highly optimized virtual machine and effectively gets its own kernel."
Myth
Reality
A container boots its own kernel
It's a process on the host's kernel; Ubuntu and Alpine reported the same one
FROM ubuntu means you run Ubuntu's kernel
You get Ubuntu's files and packages; the kernel is whatever the host runs
Rebuilding the image patches the kernel
It updates packages in the image; kernel fixes go on the host
A container is isolated like a VM
Namespaces and cgroups on a shared kernel; a VM has a kernel of its own
Docker Desktop gives each container a VM
It runs one Linux VM, and every Linux container shares its kernel
How to apply it in your project
Find out which kernel your containers run onRun docker info --format '{{.KernelVersion}}' on each host, or uname -r in any container. That's the version your security scans and kernel advisories should be checked against.
Patch on two levelsKeep host operating systems and node images updated for kernel fixes. Rebuild images regularly for the packages inside them. One doesn't replace the other.
Give every container a memory limitWithout --memory (or the equivalent in Compose or Kubernetes), one leaking container competes with all the others for the host's memory. With it, the kernel stops that one container at its limit.
Add a VM boundary for code you don't trustOur recommendation: if you run untrusted code, such as customer plugins or build jobs from outside contributors, don't rely on a shared kernel alone. Put it in separate VMs, or use Hyper-V isolation for Windows containers.
Key takeaways
A container is an isolated process with its own files, not a machine with its own kernel.
Namespaces control what a container can see; cgroups control what it can use. Both are kernel features.
All containers on a host share one kernel, so Ubuntu and Alpine containers report the same uname -r.
Kernel patches are applied to the host; rebuilding images only updates what's inside them.
VMs and containers combine: Docker Desktop runs one Linux VM, and Hyper-V isolation gives each container its own kernel.
التعليقات (0)