Skip to main content
This lesson covers core Docker security concepts you should understand before securing containers on Kubernetes. If you already know Docker-level security (namespaces, UIDs, capabilities, seccomp, LSMs), you can skip ahead. Otherwise, this primer explains how containers are isolated from the host, how user IDs are handled, and which kernel controls limit container privileges.

Process isolation and Linux namespaces

Containers share the host kernel rather than running a separate guest kernel. Linux namespaces provide the isolation: each container gets its own set of namespaces (PID, mount, network, IPC, UTS, user, etc.), so processes inside a container see only that container’s view of system resources. Example workflow to observe PID namespace isolation:
  • Start an Ubuntu container that sleeps for an hour (detached so we can inspect it from the host):
  • List processes from inside the container:
Typical output inside the container shows the sleep process as PID 1:
  • On the Docker host, the same container process appears as a regular host process (with a different PID because of the separate PID namespace). For example:
Typical host output (showing the container process with a host PID):
Key point: container processes are real host processes but are isolated via namespaces. This PID separation is how Docker implements process isolation.

Users and UIDs inside containers

A container image contains its own view of users (files like /etc/passwd and /etc/group), but by default Docker runs container processes as UID 0 (root) inside the container unless you specify otherwise. Ways to run container processes as a non-root UID:
  • Provide a UID at runtime with --user:
Output inside the container will show the process running as UID 1001:
Note: if the numeric UID has no corresponding username in the image’s /etc/passwd, tools inside the container will display the numeric UID instead of a username.
  • Bake the user into the image with a Dockerfile using the USER instruction:
Build and run:
Running container processes as non-root is a recommended best practice to limit the impact of a potential compromise.
If your application depends on specific usernames, ensure the image includes the appropriate /etc/passwd entries. Otherwise, the system will display numeric UIDs instead of names.

Is container root the same as host root?

A process running as UID 0 inside a container is root from the container’s perspective, but Docker—and the kernel—limit what that root can do on the host. Docker uses several kernel-level controls to reduce the blast radius of a compromised container:
  • Linux capabilities: split the all-powerful root privileges into fine-grained permissions (for example, CAP_NET_BIND_SERVICE, CAP_SYS_TIME, CAP_SYS_ADMIN).
  • Seccomp: syscall filtering to block dangerous system calls by default.
  • LSMs (Linux Security Modules): AppArmor or SELinux profiles can further restrict container behavior where available.
By default Docker drops many high-risk capabilities. You can adjust capability grants at runtime:
  • Add a capability:
  • Drop a capability:
  • Grant nearly unrestricted host access (strongly discouraged) with:
Table: Common runtime privilege controls For a full reference on Linux capabilities, see man 7 capabilities.
Avoid running containers with --privileged unless absolutely necessary. Instead, grant only the specific capabilities your workload requires using --cap-add and --cap-drop.

Summary

  • Containers share the host kernel; isolation relies on Linux namespaces (PID, network, mount, etc.).
  • By default, container processes run as UID 0 inside the container. Use --user or USER in a Dockerfile to run as a non-root UID.
  • Docker reduces container privileges using Linux capabilities, seccomp filters, and LSMs (AppArmor/SELinux). Prefer granting minimal capabilities over using --privileged.
Understanding these Docker-level controls is essential for securing containers on Kubernetes, because Kubernetes builds on the same kernel primitives and adds orchestration-level security policies. References and further reading
A slide titled "Security – Users" showing a host diagram on the left with nested namespaces and a Docker icon, and two user silhouette icons spaced on the right.

Watch Video