Containers and virtual machines both let you run isolated workloads on shared hardware, but they isolate at different levels. Understanding the difference explains why a VPS (a virtual machine) running Docker (containers) is such a common and effective combination.
The architecture difference
Virtual machine: a hypervisor (KVM, VMware, Hyper-V) emulates hardware. Each VM boots its own operating system kernel, with its own drivers, init system and memory.
App A | App B App C
Libs | Libs Libs
Guest OS (kernel) Guest OS (kernel)
──────── Hypervisor ────────
Host hardware
Container: processes on the host kernel, isolated with namespaces (what they can see) and cgroups (what they can use). No separate kernel; the image contains just the app and its userland libraries.
App A | App B | App C
Libs | Libs | Libs
── Container runtime ──
Host OS kernel
Host hardware
Comparison
| Virtual machine | Container | |
|---|---|---|
| Isolation boundary | Hardware virtualization, separate kernel | Shared kernel, namespaces/cgroups |
| Startup time | Tens of seconds | Milliseconds to seconds |
| Size | GBs (full OS) | MBs to hundreds of MBs |
| Overhead | Small with modern CPUs, but each VM needs OS memory | Minimal |
| Density | Dozens per host | Hundreds or thousands per host |
| OS flexibility | Any OS (Linux, Windows, BSD) | Same kernel as the host (Linux containers on Linux) |
| Kernel customisation | Yes | No |
| Security isolation | Strong | Good, but a kernel bug can affect all containers |
| Portability | VM images are large and hypervisor-specific | Images run anywhere with a compatible runtime |
| Typical unit | A server | A process/service |
Where virtual machines win
- Strong isolation between tenants — why hosting providers sell VMs (VPS), not bare containers, to customers.
- Different operating systems or kernels: Windows Server, BSD, custom Linux kernels, kernel modules (WireGuard, ZFS).
- Full system control: firewall, init system, everything you’d do on a physical server.
- Legacy applications that expect a complete OS.
Where containers win
- Packaging: an image bundles the app with exactly the libraries it needs — “works on my machine” becomes “works everywhere”.
- Speed and density: start, stop and replace services in seconds; run many on one server.
- Reproducible deployments: the same image goes from CI to staging to production.
- Microservices and scaling with orchestrators like Kubernetes or Docker Swarm.
- Clean hosts: no dependency conflicts between apps (PHP 7 and PHP 8 side by side, different Node versions).
Better together: containers inside VMs
The common pattern is both:
- A KVM VPS gives you a dedicated, isolated server with its own kernel and firewall.
- Docker on that VPS runs your apps as containers — each with its own dependencies, easily updated and moved.
You get the strong isolation of a VM between you and other customers, plus the packaging and agility of containers for your own services. Cloud Kubernetes services work the same way: containers run on VMs.
This is also why a container-based VPS (OpenVZ, LXC) is often a poor fit for Docker — nesting containers inside containers is limited. See KVM vs OpenVZ vs LXC.
Security notes
Containers share the host kernel, so:
- Keep the host kernel and Docker updated.
- Don’t run untrusted containers with
--privilegedor the Docker socket mounted. - Run container processes as non-root users; consider rootless Docker or Podman.
- Treat the host as the security boundary between workloads you don’t trust.
See Docker security best practices.
Which should you choose?
| Need | Choose |
|---|---|
| A server you control (web hosting, databases, VPN) | VM (VPS) |
| Packaging and deploying apps consistently | Containers |
| Running Windows or custom kernels | VM |
| Many small services on one server | Containers on a VM |
| Untrusted multi-tenant workloads | VMs (or hardened sandboxes like gVisor, Kata Containers) |
Start with what is a VPS and installing Docker on Ubuntu. Our Docker VPS plans run on KVM, so Docker, Compose and Kubernetes work without restrictions.