Course contentsShow
← Software Engineering
Lesson 1427 of 1,93342. Containerization and OrchestrationFree lesson

Namespaces and Control Groups

Explore Linux kernel features that enable process isolation and resource limits for containers.

Namespaces and Control Groups

You'll learn how Linux kernel features provide the foundational isolation and resource control mechanisms that make containers possible.

The Magic Behind Container Isolation

When you run a container, it feels like you're running a separate, lightweight virtual machine. But containers aren't magic—they rely on two powerful Linux kernel features: namespaces and control groups (cgroups).

Namespaces create isolated views of system resources. Think of them like soundproof rooms in a building: each container sees its own isolated environment but they're all in the same building (kernel). There are several types:

  • PID namespace: Each container sees its own process tree, with its own PID 1
  • Network namespace: Separate network interfaces, IP addresses, and routing tables
  • Mount namespace: Isolated filesystem mount points
  • UTS namespace: Separate hostname and domain name
  • IPC namespace: Isolated inter-process communication resources
  • User namespace: Maps container user IDs to different host user IDs

Without namespaces, a process in one container could see or interfere with processes in another container or the host system.

Control groups (cgroups) enforce resource limits and quotas. If namespaces create isolation, cgroups create fairness. They prevent one container from monopolizing the host's resources by limiting:

  • CPU usage (percentage or cores)
  • Memory allocation (hard and soft limits)
  • Disk I/O bandwidth
  • Network bandwidth

Without cgroups, a runaway container process could consume all available CPU or memory, starving other containers and the host system.

How They Work Together

The container runtime combines both features: namespaces isolate what a container can see, while cgroups limit how much it can consume. Together, they provide the process isolation and resource control that define modern containers.

Key Takeaway: Namespaces provide isolated views of system resources for process isolation, while control groups enforce resource limits—together they enable the lightweight, secure containerization we rely on without requiring full virtualization.