How it works · 4 of 38 Foundation
Virtual machines vs containers: what is the difference?
Sharing one computer safely
Virtual machines & containers: One big physical server is shared by many apps: a virtual machine pretends to be a whole computer with its own operating system; a container shares the server's system and packs only the app and what it needs, so it is lighter and starts faster.
Loading the animation…
Say it like this A virtual machine is a whole pretend computer with its own operating system; a container shares the server's system and packs only the app, so it's lighter, starts faster and runs the same anywhere.
Under the hood — for builders
- What's inside each
- A VM carries a whole operating system per app, on a hypervisor (the software that splits one machine into pretend ones). Containers share one operating system through a container runtime.
- Tiny VMs: Firecracker
- AWS built Firecracker to run Lambda and Fargate: VM walls, container-like speed. Figures published at launch (2018):
- The packed box: an image
- A container starts from an image: the app plus every library it needs, built from a short recipe file (a Dockerfile). Docker (2013) made this popular; the Open Container Initiative (2015) made the format a shared standard, so any runtime can run any image.
- Watch out
- Containers share one kernel (the core of the operating system), so a kernel flaw can let one reach another. A "privileged" container drops most of the walls. Code from strangers belongs in VMs or microVMs, not plain containers.
- Measure it
- Start-up time, apps per server (density) and how busy each server is (utilisation).
- Sources
- AWS Open Source Blog, "Firecracker – Lightweight Virtualization for Serverless Computing" (2018) · Agache et al., NSDI 2020 · opencontainers.org.
What happens in the virtual machines & containers animation, step by step?
- One physical server is far bigger than most apps need. How can several share it safely?
- Virtual machines: each app gets a pretend whole computer with its own operating system. Strong walls, but each one carries a full system.
- Containers: apps share the server's operating system and pack only what they need, so many more fit on one machine.
- Your turn: which starts first, the house or the box? Tap your guess.
- A container carries its app with everything it needs, so it runs the same on a laptop and in the cloud. No more 'works on my machine'.
- Your app is running. How does a phone find it, and why are its photos already nearby? Next: DNS and CDN.
What everyday example explains virtual machines & containers?
A virtual machine is a full house built inside a warehouse, with its own foundations and boiler; a container is a shipping container: a standard box you pack once, which rides on any ship and uses the ship's engine.
Why should a team care about virtual machines & containers?
Almost every modern service ships as containers; choose VMs (or microVMs) when code from strangers must be walled off strongly, containers when you want density and speed.