Watch on Instagram

Network Bytes · Episode 87 · CCNA 1.12

"Containers vs virtual machines"

A virtual machine carries a complete operating system on top of a hypervisor. A container shares the host's operating system kernel and holds just its app and files, so it is smaller and starts faster, but it is less isolated.

Posted · About a 1 minute watch, 4 minute read · Take the quiz

Virtual machines: an apartment with its own kitchen

A hypervisor lets one physical server run several virtual machines (VMs). Each VM pretends to be a whole computer, so it boots a full guest operating system, with its own kernel, drivers and system services, and then runs its app on top.

That is powerful: a VM can run Windows next to Linux on the same box, and the hypervisor keeps the VMs firmly apart. But every VM carries the weight of a whole operating system: gigabytes of disk, a chunk of memory, and a boot sequence measured in tens of seconds or minutes.

Containers: rooms in a shared house

A container packages an app together with the libraries and files it needs, and runs it as an isolated set of processes directly on the host's operating system kernel. The kernel is the core of the operating system that talks to the hardware and shares out CPU and memory.

On Linux, the kernel itself provides the walls between rooms: namespaces give each container its own view of processes, files and network interfaces, and cgroups limit how much CPU and memory each one may use. Every container uses the same kernel, like every room using the house's one kitchen.

Why containers are small and fast

Because a container leaves the operating system to the host, its image holds only the app and its dependencies, often tens of megabytes instead of gigabytes. Starting it means starting a process, not booting a computer, so containers usually start in seconds or less. And since each one needs far less memory, many more fit on one server.

The trade-off: shared walls

Sharing the kernel is also the weak spot. If an attacker finds a flaw in the shared kernel, every container on that host can be affected. VMs are separated by the hypervisor, which is a much thicker wall. That's why cloud providers often run containers inside VMs: the VM gives strong isolation between customers, and the containers give speed and density inside each VM.

One more consequence: a container needs a kernel of the right kind. Linux containers need a Linux kernel (on Windows or macOS they run inside a small Linux VM), and Windows containers need a Windows kernel.

Try it yourself

On a Linux machine, run uname -r to see your kernel version. If you have Docker installed, run docker run --rm alpine uname -r: the container reports the same kernel version as the host, because it is using the host's kernel. On Windows or macOS with Docker Desktop, it shows the kernel of Docker's small Linux VM instead. Then time it: time docker run --rm alpine true usually finishes in about a second.

Good to know

  • CCNA 1.12 lists containers with server virtualization and VRFs under virtualization fundamentals (EP78 covers virtual machines and hypervisors, EP86 covers VRFs).
  • A container packages an app with its libraries and files and runs it as isolated processes on the host's operating system kernel; on Linux the isolation comes from kernel features (namespaces for separation, cgroups for resource limits).
  • A virtual machine runs a full guest operating system, including its own kernel, on a hypervisor.
  • Container engines and orchestrators (for example Docker and Kubernetes) are beyond this short.
  • "Start in seconds" is a rule of thumb: many containers start in well under a second, while a VM has to boot a whole operating system.
  • "Less isolated" means a flaw in the shared kernel can affect every container on the host, while VMs are separated by the hypervisor; containers are often run inside VMs in the cloud to get both.
  • Linux containers on Windows or macOS run inside a small Linux VM, and Windows containers need a Windows kernel.
  • "Shared kitchen" builds on EP78's apartment-building analogy.

For CCNA learners

CCNA exam topic 1.12 is explain virtualization fundamentals, and it names containers. Know that a VM runs a full guest operating system on a hypervisor, while containers share the host's kernel, which makes them lighter and faster to start but less isolated.

Answer to the comment question

0. Containers don't carry a guest operating system: all six share the Linux host's own kernel. The host's operating system still runs, of course, but it is the host OS, not a guest, so the six guest operating systems from the VMs are gone.

Test your knowledge

Quick quiz: "Containers vs virtual machines"

4 multiple-choice questions. Pick one answer for each, then check how you did.

1What runs inside each virtual machine, on top of the hypervisor?
2What do all the containers on one host share?
3Why do containers usually start much faster than VMs?
4What is the main trade-off of containers compared with VMs?

Sources

Video transcript

Why can one server run a hundred apps without a hundred operating systems?

A virtual machine is like an apartment with its own kitchen: a complete operating system, on top of the hypervisor.

A container is like a room in a shared house. Every room uses one kitchen: the host's operating system kernel. Each room holds just its app and files.

No extra kitchens, so containers are small, start in seconds, and many more fit on one server.

The trade-off: shared walls, so containers are less isolated than virtual machines.

Six apps run in six virtual machines. You move them into containers on one Linux host. How many guest operating systems are left? Comment your answer below!

That's your byte.

More from Network Bytes

All Network Bytes lessons