All tutorials
  • #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 compete
on 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

Own plot and foundationits own slice of hardware
Own water tank and wiringits own OS and kernel
Slow and costly to buildminutes to boot, GBs on disk

Flat in a society = container

Own door and meternamespaces + cgroups
Shared foundation and plumbingone shared Linux kernel
Move in todaystarts in ~1 s, MBs on disk

Society manager = Kubernetes

Decides who gets which flatscheduler places pods
Notices a leakhealth checks
New tenant the same dayreplaces dead pods
VM = your own house. Container = a flat in a society. Kubernetes = the society's manager.

How they fit together

Physical server in a data centre

VM (a Kubernetes node)

Kubernetes: kubelet + containerd

webcontainer
webcontainer
rediscontainer
How the three sit together in a real cloud setup.

VM vs container

Virtual machines

App A + libs
App B + libs
Guest OS + kernel
Guest OS + kernel
Hypervisor
Hardware

Containers

App A + libs
App B + libs
Container runtimeDocker Engine / containerd
Host OS: ONE shared kernel
Hardware (or a VM)
The key difference: containers share one kernel instead of each booting their own OS.
Virtual machineContainer
What is fakedThe hardwareThe OS's view of itself
Own kernelYes, one per VMNo, shares the host's
Start timeSeconds to minutesAbout a second
SizeGigabytesTens to hundreds of MB
IsolationStrong (hardware level)Good (kernel is shared)
Different OS insideAny OSLinux on Linux only
Best forHard isolation, other OS, cloud nodesPackaging and shipping apps, CI, microservices

Docker vs Kubernetes

DockerKubernetes
Main jobBuild images and run containersRun and manage containers across many machines
Works onOne machineA cluster of machines (nodes)
You describeA Dockerfile (how to build) and a compose.yaml (what to run)YAML manifests (what should exist)
If a container diesRestarted only if you set a restart policy, on the same machineReplaced automatically, on another node if needed
ScalingBy hand: start more containersChange replicas, or autoscale
UpdatesStop old, start newRolling updates and one-command rollback
Learn itFirstAfter Docker

Docker Compose vs Kubernetes

Docker ComposeKubernetes
MachinesOneMany
FileOne compose.yamlSeveral YAML manifests
Self-healing across machinesNoYes
Learning curveAn afternoonWeeks to be comfortable
Great forLocal development, small single-server appsProduction systems with many services and real traffic

All four side by side

Bare metalVMContainerKubernetes
What you getA physical machineA pretend computerA walled-off processA manager for many containers
Own kernelYesYes, one per VMNo, shares the host'sNo (runs containers)
Start timeMinutes (boot)Seconds to minutesAbout a secondSeconds per pod
SizeThe whole diskGigabytesMegabytesDepends on the containers
IsolationPhysicalStrongGoodGood, plus policies
Typical useBig databases, special hardwareCloud servers, other OSesPackaging and shipping appsRunning 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)?

  1. 1Other OS or hard wall?
  2. 2Fits one machine?
  3. 3Someone to run it?
  4. 4Self-heal at scale?
  5. Answer
  • Virtual machine
  • Docker + Compose
  • Managed service
  • Kubernetes

Question 1 of 4

Do you need a different OS or kernel, or a hard security wall (untrusted code, strict compliance)?

SituationPick
Different OS, legacy app, hard isolationVirtual machine
One app or a few, one server, small teamDocker
Containers in the cloud, no team to run a clusterA managed container service (Cloud Run, AWS ECS/Fargate, Azure Container Apps)
Many services, many machines, self-healing, safe rolloutsKubernetes

What to learn, in order

  1. 01

    Linux basics

    terminal, files, processes

  2. 02

    VM 101

    what an OS and kernel are

  3. 03

    Docker 101

    images, containers, Compose

  4. 04

    Kubernetes 101

    pods, Deployments, Services

  5. 05

    A cloud

    managed Kubernetes or containers

What the market expects

My judgment, not a survey. Check it against job posts you want.

WhenWhat
Learn nowLinux 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 jobHelm/Kustomize, Gateway API, RBAC and policies, GitOps (Argo CD, Flux), monitoring and logging, cluster upgrades, cloud storage and load balancers
Skip for nowClusters 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).

  1. Time a container

    powershell
    Measure-Command { docker run --rm alpine echo hello }

    You 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.
  2. Time a VM

    powershell
    Measure-Command { multipass launch --name cmp-vm --cpus 1 --memory 1G --disk 5G }

    You should see

    It takes clearly longer than the container, even after the first download, because a whole OS boots.
  3. Whose kernel is it?

    bash
    multipass exec cmp-vm -- uname -rdocker run --rm alpine uname -r

    On Linux or macOS, also run plain uname -r to 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.
  4. Clean up

    bash
    multipass delete cmp-vm --purgedocker image rm alpinemultipass list

    You 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