CSE Roadmap

Common tier · about 3 hours · 7 parts

Part 2 of 7 · 2 min read

Containers and VMs

Think of a block of flats against a row of detached houses. In the flats, every tenant has a front door and a private space, but all share the same building, stairs and plumbing. In the houses, each family has its own roof and pipes. The flats are cheaper and quicker to build, and a fault in the plumbing floods several tenants. The analogy stops in one place: a house builder can make each house different, while all containers on a host must use the one kernel.

In plain words: A container is an ordinary process (or group of processes) that the kernel runs with namespaces for its view, a control group for its limits, a changed root directory for its files, and rights reduced by capabilities, filters and policy. It has no kernel of its own and no virtual hardware. A virtual machine has both. The differences follow from that.

Property Virtual machine Container
Kernel Its own, any version or system The host's, shared
Start Boots a kernel: seconds Starts a process: milliseconds
Size A whole disk image The files of one program
Overhead Exits, two page tables, device model Almost none: system calls run directly
Isolation Strong: guest and host kernels are apart Weaker: one kernel bug reaches all
Guest can be another OS Yes No (same kernel type)

A worked example. A server has 64 GiB of memory. A VM-based design (numbers made up to show the idea) runs 40 guests each with a 1 GiB kernel and base system in memory, using 40 GiB before any application starts. A container design runs 40 containers that share one kernel and use the file cache (Level 9) for common library files, so the fixed cost is a few hundred megabytes. This is why containers are packed more densely, and why a bug-free kernel and a strict policy matter more for containers than for VMs.

The key lines. Pick a VM when the guest needs another kernel or strong isolation between tenants who do not trust each other. Pick a container for speed and density among programs of one owner. Many systems run containers inside VMs to get both.

Container

A container is a process or group of processes run by the host kernel with its own namespaces, a control group, a separate root file system and reduced rights, so that it appears to run in its own system while it shares the host's kernel.

Example: a web server started in a container sees its own process 1, its own host name and its own files, and uses the host's kernel.

Check yourself: 1. What does a container not have that a virtual machine has? 2. Why does a container start faster? 3. Name one reason to run containers inside a VM.