Docker & Containers (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
Containers vs. Virtual Machines (VMs): How do Linux Namespaces and Control Groups (cgroups) isolate processes?
junior LevelDocker & Containers
In Simple Words:
- Virtual Machines: Virtualize physical hardware via a Hypervisor (Type 1 like ESXi or Type 2 like VirtualBox). Each VM boots a full guest OS kernel, consuming gigabytes of RAM and taking minutes to start.
- Containers: Virtualize at the operating system level. All containers share the single host Linux kernel. They run as standard Linux processes isolated by two native kernel primitives:
- Namespaces (Isolation): Restricts what a process can see. Gives each container its own process table (PID), network interfaces (NET), filesystem mounts (MNT), and user IDs (USER).
- Control Groups / cgroups (Resource Metering): Restricts how much a process can use. Enforces hard limits and quotas on CPU, RAM, disk I/O, and pids.
| Feature | Virtual Machines (VMs) | Docker Containers |
|---|---|---|
| Kernel | Separate guest kernel per VM | Shared host OS kernel |
| Startup Time | Minutes (boots full OS) | Milliseconds to seconds (starts process) |
| Resource Overhead | High (GBs of RAM reserved) | Minimal (MBs of RAM per container) |
| Isolation | Hardware-level (Hypervisor boundary) | Kernel-level (Namespaces & cgroups) |