Virtual machines and containers

Many machines in one · Part of Reliability and security

Key idea

Practice

6 questions · about 3 min

Explained step by step

Virtual machine

A virtual machine (VM) is a virtual environment that works as a computer, with its own CPU, memory, network and storage, created on physical hardware. VMs are isolated from the rest of the system, and many can run on 1 single server, for example 20. They can also be moved between servers depending on demand. It's like splitting a big house into 4 apartments: each has its kitchen and door, but the building is 1.

The main reason to use VMs is server consolidation: most apps use a small part of the hardware, for example 10%. By virtualizing, you put many virtual servers on each physical server and make better use of it, without buying more. Also, since VMs are isolated, they're good for testing new apps or setting up a production environment. It's like 4 neighbors sharing a car: nobody uses it all day, so 4 cars aren't needed.

Hypervisor

A hypervisor, also called a virtual machine monitor (VMM), is the software that separates the machine's resources from the hardware and hands them out to VMs. It treats CPU, memory and storage as a shared pool it can reassign between existing or new VMs. For example, out of 64 GB of memory it gives 8 to each of 8 VMs. It's like a building manager: they share out water, power and gas among the apartments.

Container

A container is a standard unit of software that packages code with all its dependencies, like exact versions of the runtime and libraries, so the app runs fast and the same in any environment. The app is separated from the environment it runs in, so it deploys easily and always the same way. Docker is the best-known tool. It's like a shipping container: anything goes inside, and any crane at any port lifts it the same way.

Containers have 5 advantages. They separate responsibilities: devs handle code and dependencies, and operations handles deployment. They're portable: they run almost anywhere. They isolate apps from each other at the operating system level. They make development more agile, without fighting dependencies. And they're efficient: lightweight, using only what they need. It's like a lunchbox: everyone packs their own, carries it anywhere, and it doesn't mix with anyone else's.

In virtualization, the hypervisor virtualizes the hardware: each VM carries a full guest operating system, a virtual copy of the hardware, and the app with its dependencies. Containers, instead, virtualize the operating system: each carries only the app and its dependencies, and they all share the kernel. That's why they're much lighter and use a fraction of the memory: a VM may weigh 2 GB and a container 50 MB. It's like houses versus apartments: each house has its own foundations; apartments share the building's.

Terms in this lesson

Arki, the beaver mascot

Your next interview starts with 5 minutes today.

Free on iOS and Android. Start from zero, no account needed.

Key idea

Many machines in one