Sub topic 5
The shared kernel and what it implies
This chapter assumes you know what a process is, what a kernel does, and how to use a Linux or macOS command line. It builds on the earlier chapters about containers as isolated processes.
One kernel, many processes
A virtual machine boots its own guest kernel. A container does not. Every container on a host makes system calls to the same kernel that the host uses. The kernel is the part of the operating system that manages memory, schedules processes, and talks to hardware.
You can check this on a Linux host. Both commands should print the same kernel release.
uname -r
docker run --rm alpine uname -rThe Alpine image contains Alpine's user-space files, such as the shell, libraries, and uname itself. It contains no kernel. The uname program asks the kernel for its release, and the only kernel running is the host's.
What the shared kernel gives you
- Fast start. Starting a container means creating a process. There is no firmware step and no operating system boot, so it usually takes well under a second.
- Low overhead. There is no duplicate kernel in memory for each workload, and no virtual hardware to emulate.
- High density. A host can run many more containers than VMs, because each container adds little beyond its own processes.
What the shared kernel costs you
The same design creates limits that you will run into in practice.
| Implication | What it means |
|---|---|
| Kernel version is fixed | A container cannot use a kernel feature that the host kernel lacks. Updating the image does not update the kernel. |
| Operating system family is fixed | A Linux container needs a Linux kernel. A Windows container needs a Windows kernel. |
| CPU architecture is fixed | An image built for ARM64 will not run natively on an x86-64 host without emulation. |
| Kernel settings are shared | Some settings, such as many `sysctl` values and loaded kernel modules, apply to the whole host. |
| Kernel faults are shared | A kernel bug or crash affects every container on the host. |
The last row matters most for security. Isolation inside one kernel is enforced by that kernel's own code. If a process finds a vulnerability in the kernel and exploits it, it may escape the container. A guest kernel in a VM gives a second layer, because an attacker must also get past the hypervisor. A later chapter compares the two boundaries in detail.
Distribution differences do not matter, mostly
A container can run a different Linux distribution than the host. An Alpine container can run on an Ubuntu host. What differs is user-space software: package managers, libraries, and tools. They all talk to the kernel through the same system call interface, which Linux keeps stable across releases.
The compatibility is not perfect. A program that depends on a recent system call or kernel feature can fail on an older host kernel. The error often looks like a vague "operation not permitted" or "function not implemented" message.
Restricting the kernel interface
Because every container reaches the same kernel, runtimes limit what a container may ask of it. Docker applies a default seccomp profile that blocks a set of system calls, and it drops many Linux capabilities. These controls reduce the attack surface of the shared kernel. They do not replace a separate kernel.
Exercise
A teammate builds an image on an ARM64 laptop and finds it fails to start on an x86-64 server, even though both run Linux. Which consequence of the shared kernel explains this, and why does the Linux kernel version not matter here?
Show answer
The container runs directly on the host CPU through the host kernel, so the compiled binaries in the image must match the host's CPU architecture. An ARM64 binary cannot execute on x86-64 without emulation. The kernel version is not the cause, because both hosts run Linux and the mismatch is in the instruction set.
Exercise
Why can a container start much faster than a virtual machine, and what security trade-off comes with that design?
Show answer
A container is a process on an already running kernel, so no guest operating system has to boot. The trade-off is that all containers share one kernel, so a kernel vulnerability can expose every container on the host.