Docker Kernel Isolation: 4 Proven Mechanisms, Tested

There is no Docker kernel. Every container on a host runs on the host's Linux kernel, and Docker uses features of that kernel (namespaces, cgroups, capabilities and seccomp) to make each container look like its own system. This post shows each mechanism with real output instead of diagrams. The lab ran on 20 November 2026 with Docker Engine 29.10.0 (cgroup v2) inside a docker:29-dind container on a Fedora host running kernel 7.3.4.

The Docker kernel is the host kernel

Docker kernel sharing: the same uname -r in Alpine and Debian containers, cgroup v2 limits, OOM exit 137 and capabilities
Lab output on Docker 29.10.0: one kernel, limits written as cgroup files, capability masks.
$ uname -r; docker run --rm alpine:3.22 uname -r; docker run --rm debian:13-slim uname -r
7.3.4-300.fc45.x86_64
7.3.4-300.fc45.x86_64
7.3.4-300.fc45.x86_64

The Debian image says "Debian GNU/Linux 13 (trixie)" in /etc/os-release, but it has no /boot and no kernel of its own. The image brings the userland (libc, shell, packages); the kernel is always the host's. Two practical consequences follow. A container cannot use a kernel feature the host does not have, and a kernel bug is a bug for every container at once.

Because the Docker kernel is shared, kernel settings are shared too. /proc/sys/kernel/osrelease shows the same 7.3.4 in the container, and changing a kernel-wide setting from inside is refused:

$ docker run --rm alpine:3.22 sysctl -w kernel.pid_max=100000
sysctl: error setting key 'kernel.pid_max': Read-only file system

Docker kernel isolation part 1: namespaces

Namespaces are the Docker kernel feature people meet first. Each namespace is a kernel object with an ID. Comparing the IDs from the host and from a container shows which views are separate:

host pid: pid:[4026533506]
host net: net:[4026533179]
host uts: uts:[4026533501]
host mnt: mnt:[4026533508]
container pid: pid:[4026533513]
container net: net:[4026533515]
container uts: uts:[4026533511]
container mnt: mnt:[4026533510]

All four differ, so the container has its own process tree, network stack, hostname and mount table.

PID namespace

$ docker exec sleeper ps -o pid,comm
PID   COMMAND
    1 sleep
    7 ps

PID seen from the host side: 785
  785 sleep 300

Inside, sleep is PID 1. On the host it is an ordinary process, 785. That is why the host can see and kill container processes, and why signals to PID 1 behave differently in containers. --pid=host removes this isolation: the container then saw docker-init and dockerd as PIDs 1 and 49.

UTS and network namespaces

$ docker run --rm --hostname web-01 alpine:3.22 hostname; hostname
web-01
c96b2b613922

The container got its own eth0 at 172.17.0.3 on Docker's bridge, while the host side had docker0 at 172.17.0.1. Its lo is its own loopback, not the host's.

Docker kernel isolation part 2: cgroups

With cgroup v2, Docker's resource flags are written into files the kernel enforces. Inside the container you can read them:

$ docker run --rm --memory 64m --cpus 0.5 --pids-limit 50 alpine:3.22 sh -c "cat /sys/fs/cgroup/memory.max /sys/fs/cgroup/cpu.max /sys/fs/cgroup/pids.max"
67108864
50000 100000
50

--memory 64m became 67108864 bytes, --cpus 0.5 became a quota of 50 ms per 100 ms period, and --pids-limit 50 became pids.max. Without flags the same files read max: no limit at all, which is the Docker default.

The kernel enforces them, not Docker, which is the core of the Docker kernel model:

$ docker run --rm --memory 32m --memory-swap 32m alpine:3.22 sh -c "head -c 100m /dev/zero | tail > /dev/null"; echo "rc=$?"
rc=137

$ docker run --rm --pids-limit 20 alpine:3.22 sh -c "for i in \$(seq 1 40); do sleep 30 & done"
sh: can't fork: Resource temporarily unavailable

Exit code 137 is 128 + 9: the kernel's OOM killer sent SIGKILL when the container's memory hit the limit. The fork failure is the pids controller refusing new processes. A container without these limits can exhaust the host for everyone, which is why setting them is not optional on shared machines.

Docker kernel isolation part 3: capabilities and seccomp

In the Docker kernel model, root inside a container is not full root, because Docker drops Linux capabilities and filters system calls:

$ docker run --rm alpine:3.22 grep -E "CapEff|Seccomp:" /proc/self/status
CapEff:	00000000a80425fb
Seccomp:	2

$ docker run --rm --privileged alpine:3.22 grep -E "CapEff|Seccomp:" /proc/self/status
CapEff:	000001ffffffffff
Seccomp:	0

By default the container had a reduced capability set and seccomp mode 2 (filtering). --privileged gave it every capability, turned seccomp off, and exposed the host's devices: 160 entries in /dev instead of 15. A privileged container is a root shell on the host with extra steps.

The default seccomp profile blocks some calls even for root in the container:

$ docker run --rm alpine:3.22 unshare -U true
unshare: unshare(0x10000000): Operation not permitted

With --security-opt seccomp=unconfined the same command succeeded. Dropping all capabilities shows how much ordinary root work depends on them:

$ docker run --rm --cap-drop ALL alpine:3.22 sh -c "chown 1000 /tmp; ping -c1 -W1 127.0.0.1"
chown: /tmp: Operation not permitted
ping: permission denied (are you root?)

What the Docker kernel model means for security

A virtual machine has its own kernel, so a guest kernel bug stays in the guest. Containers share one, so the isolation is only as strong as the kernel's namespaces, cgroups and filters, plus the options you pass. My order of hardening, from the cheapest to the most work:

  1. Set --memory, --cpus and --pids-limit on every container (defaults are unlimited).
  2. Never use --privileged or mount the Docker socket into containers you do not fully trust.
  3. Run as a non-root user and drop capabilities you do not need (--cap-drop ALL, then add back).
  4. Keep the default seccomp profile; do not set unconfined to make an error go away.
  5. Patch the host kernel promptly. It is the one component every container depends on.
  6. For untrusted code, use a stronger boundary: a VM per tenant or a sandboxed runtime.

The same knobs exist in Kubernetes as securityContext fields; see Kubernetes security context. Smaller images reduce what an attacker finds inside a container; see Docker hardened images. Other runtimes use the same kernel features, as shown in Docker alternatives: Podman and containerd.

FAQ

Is there a separate Docker kernel per container?

No. In the lab, Alpine and Debian containers both reported the host kernel 7.3.4-300.fc45.x86_64.

What does exit code 137 mean for a container?

The process was killed with SIGKILL, typically by the kernel OOM killer when the container hit its memory limit.

Is a Docker container as isolated as a VM?

No. A VM has its own kernel. Containers share the host kernel and rely on namespaces, cgroups, capabilities and seccomp.

Reference: namespaces(7) and Control Group v2 kernel documentation.

Comments

Popular posts from this blog

Linux Desktop Frozen? 5 Proven Fixes Before a Hard Reboot

Minecraft Bedrock on Linux: 4 Proven Ways to Play in 2026

DXVK in Wine on Linux: 7 Easy Setup Steps, Tested