How do Docker containers differ from virtual machines in architecture, disk space and how they are managed?
A VM virtualises hardware and boots its own full OS under a hypervisor; a container is an isolated process sharing the host kernel, managed by the container engine. So containers need megabytes instead of gigabytes.
| Virtual machine | Container | |
|---|---|---|
| What is virtualised | Hardware: each VM gets virtual CPU, RAM, disk, NIC | The operating system: processes get isolated views of one shared kernel |
| Guest OS | A full OS with its own kernel per VM | None; only the userland files the app needs |
| Disk space | Gigabytes per VM (whole OS image) | Megabytes (Alpine is about 8 MB); shared image layers are stored only once |
| Start time | Boots an OS, so tens of seconds to minutes | Starts a process, so well under a second |
| Managed by | A hypervisor (VMware ESXi, Hyper-V, KVM) | The container engine (Docker daemon) using kernel features (namespaces, cgroups) |
| Isolation strength | Strong: a separate kernel per VM | Weaker: one kernel bug can affect every container |
The trade-off is efficiency against isolation. Containers are cheaper and faster because they skip the guest OS, but for the same reason they all depend on the host kernel's security. Containers can also only run software for the host's kernel type (Linux containers need a Linux kernel; on Windows and macOS Docker Desktop runs a hidden Linux VM). In practice the two are often combined: containers running inside VMs.
* Each VM brings its own guest OS; containers share one host kernel. *
Go deeper:
Red Hat: What is a Linux container? — containers versus virtualization from a platform vendor.
Wikipedia: OS-level virtualization — the general technique and how it compares to hardware virtualization.
Wikipedia: Hypervisor — type 1 and type 2 hypervisors that run VMs.