Maintenance

Site is under maintenance — quizzes are still available.

Go to quizzes
Sponsored Reserved space — layout preview until AdSense is connected

Tech

How Docker Works: Namespaces, Cgroups, and Linux Isolation

Explore the underlying Linux kernel technologies—Namespaces, Cgroups, and Seccomp—that allow Docker to create isolated, lightweight containers without the overhead of a virtual machine.

June 2026 · 5 min read · 1 views · 0 hearts

Imagine your operating system as a massive apartment complex. Without isolation, every tenant could walk into any other unit, rearrange the furniture, or accidentally turn off the water for the entire building. In the world of Linux, containers are the walls, locks, and private utilities that ensure one application doesn't interfere with another, even though they all share the same foundation.

While many people think of Docker as a "lightweight virtual machine," it is fundamentally different. VMs virtualize hardware; Docker virtualizes the operating system. Here is how Linux makes that possible.

The Secret Sauce: Namespaces

If the kernel is the brain of the OS, Namespaces are the blinders. They wrap 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 that resource.

Docker utilizes several types of namespaces to create the "illusion" of a separate machine:

  • PID Namespace (Process ID): This isolates process IDs. Inside a container, your main application thinks it is PID 1 (the init process). In reality, on the host machine, it might be PID 14205. This prevents a container from seeing or killing processes running in other containers.
  • NET Namespace (Network): Each container gets its own virtual network stack, including IP addresses, routing tables, and firewall rules. This is why two different containers can both listen on port 80 without clashing.
  • MNT Namespace (Mount): This allows the container to have its own root filesystem. The container sees /etc/passwd or /var/log, but those files are entirely different from the files on the host machine.
  • UTS Namespace (Unix Timesharing System): This allows a container to have its own hostname and domain name, preventing naming conflicts across the network.
  • IPC Namespace (Inter-Process Communication): This prevents processes in one container from accessing the shared memory or message queues of another.

Enforcing Boundaries: Control Groups (cgroups)

Namespaces hide resources, but they don't limit them. Without Control Groups (cgroups), a single buggy container could trigger a memory leak that consumes all available RAM, crashing the entire host server—a scenario known as the "noisy neighbor" effect.

Cgroups act as the meter and the valve. They allow the Docker engine to set hard limits on:

  1. Memory: Limit the maximum RAM a container can use. If it exceeds this, the kernel triggers an "Out of Memory" (OOM) kill.
  2. CPU: Define how many CPU shares or cores a container can utilize, ensuring no single process hogs the processor.
  3. Disk I/O: Throttle the speed at which a container can read or write to the disk to prevent storage bottlenecks.
  4. Network Bandwidth: Control the throughput of the container's virtual network interface.

The Final Layer of Security: Capabilities and Seccomp

Even with namespaces and cgroups, a process running as root inside a container could potentially perform dangerous actions on the host kernel. To mitigate this, Linux uses a "least privilege" approach.

Linux Capabilities

Instead of giving a process full root access, Linux breaks "root power" into smaller units called Capabilities. For example, if a container only needs to bind to a port under 1024, Docker gives it the CAP_NET_BIND_SERVICE capability rather than full administrative control over the whole system.

Seccomp (Secure Computing Mode)

Seccomp acts as a firewall for system calls (syscalls). There are hundreds of ways a process can talk to the Linux kernel. Many are unnecessary for standard apps and can be used as attack vectors. Docker uses a default Seccomp profile to block risky syscalls, ensuring that even if an attacker gains control of the container, they cannot execute commands that would compromise the host kernel.

Summary: The Container Layers

To visualize how this works, think of a container as a series of concentric circles:

  • Namespaces create the visual boundary (I can't see you).
  • Cgroups create the resource boundary (I can't steal your RAM).
  • Capabilities/Seccomp create the operational boundary (I can't break the kernel).

By combining these features, Docker provides a system that is significantly faster and lighter than a VM, while remaining secure enough to run thousands of isolated applications on a single piece of hardware.

Comments

Questions, corrections, and tips stay visible for everyone reading this page.

0 in thread

Join the discussion

Shown next to your comment.

Up to 4,000 characters

No comments yet

Be the first to leave a note — it helps the next reader.