A container gives weaker isolation than a virtual machine. It is a process on the host kernel wearing a set of namespaces and cgroups. So when that process runs as root, which it does by default, you are one kernel bug or one misconfiguration away from root on the host. Running as root remains the most common container hardening failure because nothing forces you to fix it and everything works until it does not.

When you write a Dockerfile with no USER instruction, the resulting container runs its main process as UID 0. That UID is the same UID 0 the kernel knows on the host; user namespaces, which would remap it, are off by default in most runtimes. Inside the container the process has a restricted capability set, but a restricted capability set is still a set, and the attack surface it shares with every other tenant is the host kernel itself.

What root inside a container actually buys an attacker

Why Running Containers as Root Is Still the #1 MistakeDiagram with these labels, in reading order: CONTAINER; KERNEL BOUNDARY; HOST; RCE inherits root; escape is cheap; if unprivileged; Attacker; RCE in the app; Process as UID 0; full root caps; Shared host kernel; runtime bug /; misconfig; Not set; Non-root, drop caps,; userns; Root on the host; RCE inherits root →.CONTAINERKERNEL BOUNDARYHOSTRCE inherits rootescape is cheapif unprivilegedAttackerRCE in the appProcess as UID 0full root capsShared host kernelruntime bug /misconfigNot setNon-root, drop caps,usernsRoot on the hostRCE inherits root →escape is cheap
How UID 0 in a container turns one app bug into root on the host.

Suppose an attacker achieves remote code execution in your application, such as a deserialization bug or an SSRF that reaches an internal admin endpoint. If the process is root, they inherit its capabilities. They can write to any bind-mounted host path the container was granted, read secrets mounted into the filesystem, install tooling, and probe for a kernel or runtime flaw to break out entirely. Container escapes such as the 2019 runc overwrite (CVE-2019-5736), which needs the attacker to run commands as root inside a container, show why root in the container matters. The 2024 'Leaky Vessels' runc flaw (CVE-2024-21626) is a separate container escape that a non-root user does not fix on its own, so patch the runtime too.

Run the same process as an unprivileged UID and most of that collapses. The attacker cannot write to root-owned host mounts, cannot bind low ports, and hits permission denials on the very syscalls an escape needs. This does not guarantee safety, but it removes the cheapest paths first.

Why it matters: Root in a container is UID 0 on the host kernel with a reduced capability set. Dropping to a non-root UID is among the cheapest changes you can make to a container image, and it costs one line.

Fixing it in the image and at admission

  • Set a numeric USER in the Dockerfile. Prefer a high, explicit UID (for example USER 10001) over a username, so admission policies that check runAsNonRoot can evaluate it without resolving /etc/passwd.
  • Enforce it in the pod spec. Set securityContext.runAsNonRoot: true and a concrete runAsUser; the kubelet will refuse to start a container that tries to run as UID 0.
  • Drop capabilities to the floor. Add capabilities.drop: ["ALL"] and add back only what the workload provably needs. Most web services need none.
  • Make the root filesystem read-only. readOnlyRootFilesystem: true plus explicit emptyDir writable mounts stops an attacker planting a binary where the app will re-execute it.
  • Block privilege escalation. allowPrivilegeEscalation: false prevents a setuid binary inside the image from regaining capabilities the runtime dropped.
The fix in a Dockerfile and a pod securityContext# Dockerfile
RUN adduser -D -u 10001 app
USER 10001

# pod spec
securityContext:
  runAsNonRoot: true
  runAsUser: 10001
  allowPrivilegeEscalation: false
  readOnlyRootFilesystem: true
  capabilities: { drop: [ "ALL" ] }

Why it persists

Root-by-default survives because of friction. A base image expects to write to /var; an init script wants to chown; a legacy service binds port 80. Each is solvable: pre-create writable directories, bind a high port and remap it at the service, or use file capabilities instead of full root. Each takes a few minutes, and 'it works' dulls the urge to fix it. Make non-root the default your platform ships, so every new image inherits it and opting back into root is an exception that gets reviewed.

None of this helps the workloads you do not know are running. A team that spun up a container on a forgotten node, as root, with a host mount, is exactly the blind spot an attacker finds first, and you cannot harden what you have not discovered.

Back to the knowledge baseRequest an assessment