InterviewHubPRO
Section Overview
Q2

Question 2 of 50

Part 1: Candid Experience, Container Internals & Docker (1 - 10)

4%
DevOps & Kubernetes (50 Qs)•Part 1: Candid Experience, Container Internals & Docker (1 - 10)

Containers vs. Virtual Machines: How do Linux Namespaces and Control Groups (cgroups) isolate processes?

Direct Architecture Explanation

A Virtual Machine (VM) virtualizes hardware through a hypervisor (Type 1 or Type 2) and runs a completely separate guest operating system with its own kernel. A container virtualizes the operating system; it runs as a standard Linux process directly on the host kernel, isolated by kernel features: Namespaces (what the process can see) and cgroups (what the process can use).

sql
       +-----------------------+               +-----------------------+
       |   Virtual Machine     |               |       Container       |
       |  +-----------------+  |               |  +-----------------+  |
       |  | App & User Space|  |               |  | App & User Space|  |
       |  +-----------------+  |               |  +-----------------+  |
       |  |  Guest Kernel   |  |               |  | Linux Namespaces|  |
       |  +-----------------+  |               |  | & cgroups Limits|  |
       |  | Virtual Hardware|  |               |  +-----------------+  |
       +-----------------------+               +-----------------------+
                   |                                       |
                   v                                       v
       +-----------------------+               +-----------------------+
       |       Hypervisor      |               |      Host Kernel      |
       +-----------------------+               +-----------------------+
       |      Host Hardware    |               |     Host Hardware     |
       +-----------------------+               +-----------------------+

1. Linux Namespaces (Visibility Boundaries)

NamespaceFlagIsolation Provided
PIDCLONE_NEWPIDProcess IDs. Container process sees itself as PID 1, isolated from host PIDs.
NETCLONE_NEWNETNetwork devices, IP addresses, IP routing tables, port bindings, and firewall rules.
MNTCLONE_NEWNSFilesystem mount points. Container sees its own isolated root filesystem (chroot / pivot_root).
IPCCLONE_NEWIPCSystem V IPC and POSIX message queues, shared memory segments.
UTSCLONE_NEWUTSHostname and NIS domain name.
USERCLONE_NEWUSERMaps container UID 0 (root inside container) to non-root UID (e.g. UID 10001) on the host.

2. Control Groups (cgroups v1 & v2 Resource Metering)

While Namespaces restrict visibility, cgroups restrict resource consumption:

  • CPU limits: Enforced via the Linux Completely Fair Scheduler (CFS) quota (cpu.cfs_quota_us and cpu.cfs_period_us).
  • Memory limits: Enforced via memory.max (cgroups v2) or memory.limit_in_bytes (v1). If a container exceeds this, the kernel OOM killer terminates it (OOMKilled / exit code 137).
  • Block I/O & PIDs: Restricts disk read/write bandwidth (io.weight) and limits maximum process counts (pids.max) to block fork-bombs.