Containers vs virtual machines
A VM virtualizes hardware and boots its own kernel. A container is a process on the host's kernel. What that costs, what it buys, and when you want both.
Containers vs virtual machines
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A virtual machine emulates hardware. A hypervisor gives each guest virtual CPUs, memory and disks, and every guest boots its own kernel.
- A container is a group of ordinary processes on the host's kernel, fenced off by namespaces and limited by cgroups. Nothing boots.
- The difference shows up in size and start time. Alpine's VM release is a 70 MB ISO with a kernel and initramfs, while its container image is a 3.9 MB layer with no kernel at all.
- The shared kernel is also the weak point. One kernel bug reachable from inside a container can affect every container on the host.
- A container needs a kernel of the right type, so Linux images on a Mac or Windows run inside a hidden Linux VM.
- Production usually layers the two. Containers run inside VMs, and microVM runtimes such as Firecracker and Kata give each container its own small kernel when tenants don't trust each other.
One server, many apps
You have one big server and five apps. They need different versions of Python, OpenSSL and a database client, and one of them leaks memory under load. Put them all straight on the host and they trip over each other: an upgrade for one breaks another, and the leaky one starves the rest.
There are two ways to give each app its own space. You can carve the machine into several fake machines, or you can keep one machine and fence off its processes. The first is a virtual machine. The second is a container. Docker is built on the second, and knowing why it differs from the first explains most of what Docker can and can’t promise you.
A VM fakes the hardware
A hypervisor sits between the physical hardware and one or more guest operating systems. It hands each guest virtual CPUs, a slice of memory, a virtual disk and a virtual network card. KVM on Linux, Hyper-V, VMware ESXi and Xen are hypervisors. The guest doesn’t know or care that its hardware is fake. It runs firmware, boots its own kernel, starts its own init system, and only then starts your app.
That gives strong isolation. Two guests share nothing but the hypervisor, which is a small, heavily audited piece of code. The price is weight: every guest carries a full kernel and OS, reserves memory up front, and takes seconds to boot.
A container fences off processes
A container doesn’t fake any hardware. Its processes are ordinary processes on the host’s kernel. The kernel uses namespaces to give them a private view of process IDs, mounts, network interfaces and hostname, and cgroups to cap what they can use. An image supplies the root filesystem. Nothing boots. Starting a container means starting a process, which is why it takes milliseconds rather than seconds.
Think of a block of flats against a row of detached houses. The houses (VMs) each have their own foundations, plumbing and roof. The flats (containers) share one foundation and one set of pipes, with walls and locked doors between them. Flats are cheaper and quicker to build. A crack in the shared foundation affects every flat at once.
The devops lesson on containers shows the process view in more detail. Here the point is the comparison.
What the difference looks like on disk
Alpine Linux ships both: an ISO for VMs and an image for containers. I downloaded the VM release, alpine-virt-3.24.4-x86_64.iso, and listed its boot files:
$ ls -l virt.iso # 70,254,592 bytes
$ bsdtar -tvf virt.iso | grep -E 'boot/(vmlinuz|initramfs|modloop)-virt$'
-r--r--r-- 1 0 0 9845700 Nov 5 14:56 boot/initramfs-virt
-r--r--r-- 1 0 0 22990848 Nov 5 14:56 boot/modloop-virt
-r--r--r-- 1 0 0 12649472 Nov 5 14:56 boot/vmlinuz-virt
A 12.6 MB kernel, a 9.8 MB initramfs and 23 MB of kernel modules, all needed to boot a machine. Then I pulled alpine:latest for linux/amd64 from Docker Hub’s registry API. It is one layer of 3,853,673 bytes compressed. Unpacked, it has no /boot directory and no kernel, just 8.3 MB of files:
$ ls alpine-root
bin dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
$ file alpine-root/bin/busybox
ELF 64-bit LSB pie executable, x86-64, ... interpreter /lib/ld-musl-x86_64.so.1
The same gap appears for Ubuntu: the 26.04 cloud image for VMs is 861,563,904 bytes, while the ubuntu:latest container image (also 26.04) is 42 MB compressed. The container borrows the kernel it lands on.
What the shared kernel costs
Borrowing the kernel has two consequences.
- The kernel must match. That
busyboxbinary is a Linux x86-64 program. It can’t run on macOS or Windows directly, which is why Docker Desktop runs a Linux VM behind the scenes on those systems, and why anamd64image on an Apple silicon Mac also needs CPU emulation. - The kernel is a shared attack surface. Linux has hundreds of system calls. A bug in any of them that is reachable from inside a container can be a way out. CVE-2019-5736, a runc bug that let a container overwrite the host’s runc binary, is the standard example. Hardening helps, and the security group covers it, but it narrows the gap rather than closing it.
Using both
Real systems rarely pick one. Cloud servers are VMs, and you run containers inside them: the VM separates customers, the containers separate your apps. When even that isn’t enough, for example running untrusted code from many customers on one host, microVMs wrap each container in its own tiny VM. Firecracker, which runs AWS Lambda, says it boots a microVM in under 125 ms with under 5 MiB of overhead. Kata Containers plugs the same idea into ordinary container tooling. gVisor takes a third route, intercepting a container’s system calls with a user-space kernel. You keep images and the container workflow, and buy back VM-grade isolation with some speed.
About the video
The embed is all of LearnThatStack’s “Containers Don’t Exist - Your Kernel Is Lying to You”, February 2026, 9 minutes. Its chapters move from virtual machines to containers, then what follows from the difference, then proving it. The description says it covers namespaces, cgroups and the setns call behind docker exec, why Docker on a Mac has slower volume mounts, why AWS Lambda uses Firecracker, and what CVE-2019-5736 showed. Its namespace detail overlaps the Linux lessons linked above, which go further. English was judged from the title, description and its English caption track. Dave’s Garage in deeper is the gentler comparison, with more on hypervisors and snapshots.
What was run: the Alpine ISO was downloaded and listed with bsdtar, the Alpine container layer was pulled from Docker Hub’s registry API by a short Python client, hash-checked and unpacked, and the Ubuntu cloud image size was read from its HTTP Content-Length. There is no Docker or VM on this machine, so nothing was booted or started. Start-time figures and the Firecracker boot time come from the projects’ own documentation, not from a measurement here.
Where this fits
This is the first lesson of the roadmap. Next, the pieces that turn docker run into a running process: the Docker architecture.
Check yourself
Why does a container start in well under a second while a VM takes much longer?
Starting a container is starting a process on a kernel that is already running. A VM has to run firmware, boot a kernel and an init system before your app starts.
An image built on an x86 Linux laptop runs on an x86 Linux server but not natively on an M-series Mac. Why?
The image holds Linux x86-64 binaries and no kernel. The Mac has a different kernel and CPU, so Docker Desktop runs a Linux VM, and an x86 image there also needs CPU emulation.
Two customers who don't trust each other want to run code on your host. Why is a plain container a weaker boundary than a VM?
Both containers share one host kernel, so a kernel exploit from one reaches the other. A VM puts a separate guest kernel and a hypervisor between them, which is a much smaller attack surface.
What does a microVM runtime like Firecracker or Kata change about a container?
The container's processes run inside a tiny VM with its own kernel, so you keep the container workflow and image format but get hardware-virtualization isolation.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.