- #docker
- #kubernetes
- #vm
Docker vs Kubernetes vs VM: What Each One Is For
How virtual machines, Docker and Kubernetes differ, how they stack together, the common mix-ups, and which one to use when. With a quick hands-on test of start time and kernels.
Akshit Bansal7 min readTutorial 4
they stack, not competeon this page
In one minute
Virtual machine
- A whole computer made of software, with its own OS
- Boots in seconds to minutes, takes GBs
- Use for a hard wall or a different OS
Docker
- Packs one app and its files into an image
- Runs it as a walled-off process in about a second
- Use to ship any app the same way everywhere
Kubernetes
- Runs many containers across many machines
- Restarts, scales and updates them for you
- Use when one machine is not enough
New to any of them? Each has its own beginner tutorial: VM 101, Docker 101, Kubernetes 101.
Words you need
Bare metal
One operating system running straight on a physical machine, with nothing virtual in between.
Like owning a whole plot of land
Kernel
The core of an operating system: it runs every program and controls the hardware.
Like the foundation and plumbing of a building
Virtual machine (VM)
A pretend computer with its own OS and kernel, running on a real one.
Like an independent house
Container
An app running as a walled-off process that shares the host's kernel.
Like a flat in an apartment block
Orchestration
Automatically starting, placing, healing, scaling and updating many containers on many machines.
Like the society manager running all the flats
Node
One machine (often a VM) in a Kubernetes cluster.
Like one building in the society
One picture for all three
Independent house = VM
Flat in a society = container
Society manager = Kubernetes
How they fit together
Physical server in a data centre
VM (a Kubernetes node)
Kubernetes: kubelet + containerd
VM vs container
Virtual machines
Containers
| Virtual machine | Container | |
|---|---|---|
| What is faked | The hardware | The OS's view of itself |
| Own kernel | Yes, one per VM | No, shares the host's |
| Start time | Seconds to minutes | About a second |
| Size | Gigabytes | Tens to hundreds of MB |
| Isolation | Strong (hardware level) | Good (kernel is shared) |
| Different OS inside | Any OS | Linux on Linux only |
| Best for | Hard isolation, other OS, cloud nodes | Packaging and shipping apps, CI, microservices |
Docker vs Kubernetes
| Docker | Kubernetes | |
|---|---|---|
| Main job | Build images and run containers | Run and manage containers across many machines |
| Works on | One machine | A cluster of machines (nodes) |
| You describe | A Dockerfile (how to build) and a compose.yaml (what to run) | YAML manifests (what should exist) |
| If a container dies | Restarted only if you set a restart policy, on the same machine | Replaced automatically, on another node if needed |
| Scaling | By hand: start more containers | Change replicas, or autoscale |
| Updates | Stop old, start new | Rolling updates and one-command rollback |
| Learn it | First | After Docker |
Docker Compose vs Kubernetes
| Docker Compose | Kubernetes | |
|---|---|---|
| Machines | One | Many |
| File | One compose.yaml | Several YAML manifests |
| Self-healing across machines | No | Yes |
| Learning curve | An afternoon | Weeks to be comfortable |
| Great for | Local development, small single-server apps | Production systems with many services and real traffic |
All four side by side
| Bare metal | VM | Container | Kubernetes | |
|---|---|---|---|---|
| What you get | A physical machine | A pretend computer | A walled-off process | A manager for many containers |
| Own kernel | Yes | Yes, one per VM | No, shares the host's | No (runs containers) |
| Start time | Minutes (boot) | Seconds to minutes | About a second | Seconds per pod |
| Size | The whole disk | Gigabytes | Megabytes | Depends on the containers |
| Isolation | Physical | Strong | Good | Good, plus policies |
| Typical use | Big databases, special hardware | Cloud servers, other OSes | Packaging and shipping apps | Running many services in production |
Common mix-ups
- "A container is a lightweight VM." No. A VM boots its own OS; a container is a process on the host's kernel.
- "Kubernetes replaces Docker." No. Docker builds images; Kubernetes runs them on a cluster.
- "Containers are always safer than VMs." No. VMs have the stronger wall, because each has its own kernel.
- "Docker on my Mac runs without a VM." No. Docker Desktop runs a hidden Linux VM, because macOS has no Linux kernel.
- "Every project needs Kubernetes." No. One server and Docker Compose run a lot of real products.
Which one do I use?
Do you need a different OS or kernel, or a hard security wall (untrusted code, strict compliance)?
- 1Other OS or hard wall?
- 2Fits one machine?
- 3Someone to run it?
- 4Self-heal at scale?
- Answer
- Virtual machine
- Docker + Compose
- Managed service
- Kubernetes
- Do you need a different OS or kernel, or a hard security wall (untrusted code, strict compliance)?
- Yes:
- → Use a virtual machine
- No:
- Is it one app or a handful of services that fit on one machine?
- Yes:
- → Use Docker + Compose
- No:
- Is there someone to run a cluster, or a managed one (EKS, GKE, AKS) your company already pays for?
- Yes:
- Do you need self-healing, rolling updates and autoscaling across many machines?
- Yes:
- → Use Kubernetes
- No:
- → Use a managed container service
- No:
- → Use a managed container service
| Situation | Pick |
|---|---|
| Different OS, legacy app, hard isolation | Virtual machine |
| One app or a few, one server, small team | Docker |
| Containers in the cloud, no team to run a cluster | A managed container service (Cloud Run, AWS ECS/Fargate, Azure Container Apps) |
| Many services, many machines, self-healing, safe rollouts | Kubernetes |
What to learn, in order
- 01
Linux basics
terminal, files, processes
- 02
VM 101
what an OS and kernel are
- 03
Docker 101
images, containers, Compose
- 04
Kubernetes 101
pods, Deployments, Services
- 05
A cloud
managed Kubernetes or containers
What the market expects
My judgment, not a survey. Check it against job posts you want.
| When | What |
|---|---|
| Learn now | Linux CLI, Git, Dockerfiles, Compose, debugging containers, YAML, kubectl get/describe/logs/apply/exec/port-forward/rollout, Pod/Deployment/Service/ConfigMap/Secret, probes and limits |
| Learn on the job | Helm/Kustomize, Gateway API, RBAC and policies, GitOps (Argo CD, Flux), monitoring and logging, cluster upgrades, cloud storage and load balancers |
| Skip for now | Clusters from scratch, service meshes, writing operators, multi-cluster, Docker Swarm |
DIY: see the difference yourself
Two short experiments: how fast each one starts, and whose kernel it uses. You need Docker (see Docker 101) and Multipass (see VM 101).
Time a container
Measure-Command { docker run --rm alpine echo hello }time docker run --rm alpine echo hellotime docker run --rm alpine echo helloYou should see
It prints hello. The first run includes downloading the small alpine image; run it again and it usually finishes in about a second.Time a VM
Measure-Command { multipass launch --name cmp-vm --cpus 1 --memory 1G --disk 5G }time multipass launch --name cmp-vm --cpus 1 --memory 1G --disk 5Gtime multipass launch --name cmp-vm --cpus 1 --memory 1G --disk 5GYou should see
It takes clearly longer than the container, even after the first download, because a whole OS boots.Whose kernel is it?
multipass exec cmp-vm -- uname -rdocker run --rm alpine uname -rOn Linux or macOS, also run plain
uname -rto see your own machine's kernel. On Linux it matches the container's line.You should see
The VM prints its own Ubuntu kernel version. The container prints the kernel it is sharing: your own on Linux, or Docker Desktop's hidden VM on Windows and macOS.Clean up
multipass delete cmp-vm --purgedocker image rm alpinemultipass listYou should see
multipass list no longer shows cmp-vm.
If a command fails, the fixes are in the troubleshooting sections of VM 101 and Docker 101.
Sources
- Docker docs, "What is a container?": docs.docker.com/get-started/docker-concepts/the-basics/what-is-a-container (opens in a new tab)
- Kubernetes overview: kubernetes.io/docs/concepts/overview (opens in a new tab)
- Dockershim removal: kubernetes.io/blog/2022/02/17/dockershim-faq (opens in a new tab)
- roadmap.sh Docker (opens in a new tab) and Kubernetes (opens in a new tab) roadmaps
- Videos this was planned around: Docker vs virtual machines (opens in a new tab) by IBM Technology, Kubernetes vs Docker (opens in a new tab) by NextWork