Containers & Virtualization
Virtualization and containerization are foundational technologies for modern cloud computing. Understanding these concepts is essential for senior engineers designing scalable, isolated, and efficient systems.Interview Frequency: Very High
Key Topics: Namespaces, cgroups, Docker internals, hypervisors
Time to Master: 12-15 hours
Key Topics: Namespaces, cgroups, Docker internals, hypervisors
Time to Master: 12-15 hours
Virtualization Overview
Linux Namespaces
Namespaces provide isolation of global system resources. Each namespace type isolates a different aspect of the system.Namespace Types
PID Namespace
Network Namespace
Mount Namespace
Creating Namespaces
Using cgroups
systemd and cgroups
Container Architecture
How Containers Work
Container Runtime Stack
Building a Container from Scratch
Virtual Machines
Hypervisor Types
KVM (Kernel-based Virtual Machine)
Hardware Virtualization Extensions
Memory Virtualization
Containers vs VMs
When to Use Each
| Use Case | Recommendation |
|---|---|
| Microservices | Containers |
| Dev/Test environments | Containers |
| CI/CD pipelines | Containers |
| Multi-tenant with untrusted code | VMs |
| Running Windows on Linux | VMs |
| Legacy applications | VMs |
| Maximum isolation | VMs |
| Serverless functions | Containers or microVMs |
Hybrid: MicroVMs and Kata Containers
Interview Questions
How do containers provide isolation?
How do containers provide isolation?
Answer:
Containers use multiple Linux kernel features:
- Namespaces - Isolate system resources:
- PID: Separate process tree
- Network: Own network stack
- Mount: Own filesystem view
- User: Separate UID/GID mapping
- cgroups - Limit resources:
- CPU time
- Memory
- I/O bandwidth
- Number of processes
- Seccomp - Filter system calls
- Capabilities - Fine-grained privileges
- OverlayFS - Layered filesystem
What is the difference between a container and a VM?
What is the difference between a container and a VM?
Key differences:
Containers share the host kernel; VMs have their own kernel.
Use VMs when you need different OS or stronger isolation.
Use containers for fast, lightweight deployment.
| Aspect | Container | VM |
|---|---|---|
| Isolation | Process-level (shared kernel) | Hardware-level (own kernel) |
| Boot time | Seconds | Minutes |
| Overhead | Minimal | 2-10% |
| Size | MBs | GBs |
| Security | Weaker isolation | Stronger isolation |
How does Docker networking work?
How does Docker networking work?
Answer:Docker uses network namespaces and virtual ethernet (veth) pairs:
- Bridge mode (default):
- docker0 bridge on host
- Each container gets a veth pair
- One end in container, one on bridge
- NAT for external access
- Host mode:
- Container shares host network namespace
- No isolation, but no overhead
- Overlay:
- Multi-host networking
- VXLAN encapsulation
- Used by Docker Swarm/Kubernetes
Explain how cgroups work
Explain how cgroups work
Answer:cgroups (control groups) limit and account for resource usage:cgroup v2 unified hierarchy is now preferred over v1’s multiple hierarchies.
- Hierarchy: Tree structure of process groups
- Controllers: cpu, memory, io, pids, etc.
- Limits: Set via pseudo-filesystem (
/sys/fs/cgroup)