Kubernetes vs Docker: What Each Does and When You Need Both
DEV Community

Kubernetes vs Docker: What Each Does and When You Need Both

Bottom Line: One Machine vs Many

Docker and Kubernetes do 2 different jobs, and the choice you are really making is between 1 machine and many.

Bottom line: Docker = build an image and run it as a container on 1 machine. A laptop, a CI runner or a single server. Kubernetes = keep containers running across many machines. It places them, restarts them, replaces them and routes traffic to them.

They work together. You build the image with Docker, push it to a registry, and Kubernetes runs it.

Kubernetes stopped using Docker Engine in v1.24. Nodes on EKS, GKE and AKS run containerd. Your Docker-built images run on it unchanged.

The real comparisons are Docker Compose vs Kubernetes and Docker Swarm vs Kubernetes. Both come down to how many machines you have to survive losing.

Docker vs Kubernetes at a Glance

  • Docker Kubernetes Job: Build images, run containers / Run containers across a cluster
  • Scope: 1 machine by default / Up to 5,000 nodes
  • You write: A Dockerfile, a compose.yaml / YAML manifests
  • If the machine dies: The app is down / Pods are rescheduled on other nodes
  • Price of the software: Engine is free and open source / Open source. A managed control plane is $0.10 an hour

Docker = 1 machine. Kubernetes = many.

What to Do, by Where You Are Today

  • Your situation: 1 product, 1 server, a small team. What I would do: Docker Compose with a restart policy and a healthcheck
  • Containers in the cloud and nobody to run a platform: ECS on Fargate, Cloud Run or Azure Container Apps
  • Several teams, many services, deploys every day: Managed Kubernetes: EKS, GKE or AKS
  • Already on Docker Swarm and it works: Stay. Plan the move the day you need something it lacks
  • On Kubernetes with scripts that call docker on the nodes: Replace them with kubectl and crictl

Deciding whether your product needs Kubernetes yet? Book a free consultation call to examine what it would take to get your DevOps setup production-grade: environments, deployments, monitoring, security, and costs.

Find your situation:

  • You want the 2 definitions in plain words: what Docker does and what Kubernetes does
  • Someone told you Kubernetes dropped Docker: what changed in v1.24
  • You want to see the code: the same web server, 4 ways
  • You run Compose in production and wonder how long it lasts: Docker Compose vs Kubernetes
  • You are choosing a platform this quarter: the 5 questions

Docker Builds and Runs Containers on 1 Machine

Docker is 4 things that people call by 1 name.

  • A build tool. docker build reads a Dockerfile and produces an image
  • An image format. An image is a package of everything the app needs to start: OS files, runtime, dependencies, code
  • A registry. Docker Hub stores images so other machines can pull them
  • An engine. Docker Engine runs the image as a container on the machine it is installed on

A container, in Docker's own words, is "an ordinary process on your computer" that runs in isolation. It shares the machine's kernel, which is what makes it lighter than a virtual machine.

Inside Docker Engine there are 3 layers: dockerd (the daemon and its API) → containerd (the container lifecycle) → runc (starts the process). Remember containerd. It comes back in the Kubernetes story.

Docker Desktop is the app for Mac, Windows and Linux that bundles the Engine, the CLI, Compose and a local Kubernetes. Docker Engine is free and open source. Docker Desktop needs a paid subscription for companies with 250 or more employees or $10 million or more in annual revenue.

Docker = 1 machine. Out of the box, everything Docker Engine does, it does on the host it runs on. (Swarm mode, further down, is the exception you switch on.)

Kubernetes Keeps Containers Running Across Many Machines

The Kubernetes site defines it as "an open source system for automating deployment, scaling, and management of containerized applications." In simple words: you tell Kubernetes what should be running, and it keeps it running across a group of machines.

A cluster has 2 parts:

  • The control plane: the API server, etcd (the database), the scheduler and the controllers
  • The nodes: machines that run your containers. Each one runs a kubelet and a container runtime

What it does that a single Docker host does not:

  • Scheduling. You say how much CPU and memory a container needs. Kubernetes picks the node
  • Self-healing. A failed container is restarted. A failed node's workloads are rescheduled on other nodes
  • Rollouts and rollbacks. New Pods come up while old ones go down, at a controlled rate. By default at most 25% are unavailable at a time
  • Service discovery and load balancing. A Service gives a changing set of Pods 1 stable name
  • Autoscaling. More Pods when CPU rises, more nodes when Pods do not fit. Both need an add-on: Metrics Server and a node autoscaler
  • Config and secrets. Changed without rebuilding the image

Kubernetes v1.37 supports clusters of up to 5,000 nodes and 150,000 Pods.

The docs also list what Kubernetes is not, and this is the part most comparisons skip:

  • It "does not deploy source code and does not build your application". You still need something that builds images
  • It "does not dictate logging, monitoring, or alerting solutions". You bring those
  • It does not come with a database, a cache or a message bus
  • A Service of type LoadBalancer needs a cloud, or a load balancer you provide: "Kubernetes does not directly offer a load balancing component"

Kubernetes = many machines that behave like 1. You pay for that with moving parts.

Kubernetes Stopped Using Docker Engine in v1.24

In December 2020 the Kubernetes project announced it was deprecating Docker as a container runtime. The internet read it as "Kubernetes is dropping Docker". The project later admitted: "We didn't do a great job communicating this".

What actually happened:

  • In the early days Kubernetes supported 1 runtime: Docker Engine
  • Kubernetes then defined the Container Runtime Interface (CRI), so the kubelet could talk to any runtime
  • Docker Engine does not speak CRI, so Kubernetes carried an adapter inside the kubelet, called dockershim
  • v1.20 announced the removal of dockershim. v1.24 removed it
  • Nodes now run a CRI runtime directly, and the common one is containerd

Before v1.24, with Docker as the runtime: kubelet → dockershim → Docker Engine → containerd → runc. Since v1.24: kubelet → containerd → runc.

The 2 pink boxes left the chain. containerd and runc stayed. Kubernetes cut out the middle of the chain. The part that starts your container was containerd before, and it is containerd now.

The 3 big managed services agree: EKS-optimized Amazon Linux images come with containerd, GKE uses containerd on all node images, and AKS uses containerd on Linux node pools.

Your Docker Images Still Run

The Kubernetes blog, in a post titled "Don't Panic: Kubernetes and Docker": "Docker-produced images will continue to work in your cluster with all runtimes, as they always have."

Why? An image built by Docker is an Open Container Initiative (OCI) image. containerd and CRI-O both pull and run OCI images. Docker on your laptop and in your CI is unaffected. Building with Docker does not make you depend on Docker as a runtime.

What changes on a node:

  • docker ps and docker exec do not see Kubernetes containers. They are "not visible to Docker"
  • An image you build with docker build on a node is invisible to Kubernetes until you push it to a registry
  • A Pod that mounts /var/run/docker.sock to build images breaks
  • Monitoring or security agents that expect Docker Engine on the node need a version that talks to containerd

The replacements:

# Which runtime does each node use? Read the CONTAINER-RUNTIME column
kubectl get nodes -o wide
# On the node itself, instead of docker ps
crictl ps -a

You can still run Docker Engine under Kubernetes through an adapter called cri-dockerd, maintained by Mirantis and Docker. I would only do it for a workload that truly needs the Docker socket.

containerd vs Docker Is a Part vs the Whole

containerd was born at Docker in 2014 as the lower layer of the Docker engine. Today it is a graduated Cloud Native Computing Foundation (CNCF) project. Docker Engine = containerd + a build tool + a CLI + an API + networking and volumes for 1 host. A Kubernetes node needs only the first item on that list.

GKE says it plainly: "You cannot use containerd to build container images." So you keep both: Docker where images are built, containerd where they run.

The Same Web Server in Docker, Compose, Swarm and Kubernetes

4 ways to run nginx, from the smallest to the largest. Every command and field below is taken from the Docker and Kubernetes references.

  1. docker run: 1 container
docker run -d -p 8080:80 --name web --restart unless-stopped nginx

-d runs it in the background, -p 8080:80 publishes container port 80 on host port 8080, and --restart unless-stopped brings it back after a crash or a reboot.

  1. Docker Compose: 1 application on 1 host
# compose.yaml
services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost"]
      interval: 1m30s
      timeout: 10s
      retries: 3
docker compose up -d

The command in test runs inside the container, so the image has to contain it.

  1. Docker Swarm: several hosts, Docker commands
docker swarm init --advertise-addr
docker service create --name web \
  --replicas 3 \
  --publish published=8080,target=80 \
  nginx
docker service update --image nginx:stable web
docker service update --rollback web
docker service scale web=5

Port 8080 answers on every node of the swarm, including nodes that run no copy of the service.

  1. Kubernetes: a cluster, declared in YAML
# web.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  labels:
    app: web
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
        - name: web
          image: nginx:latest
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: web
spec:
  type: LoadBalancer
  selector:
    app: web
  ports:
    - port: 80
      targetPort: 80
kubectl apply -f web.yaml
kubectl rollout status deployment/web
kubectl set image deployment/web web=nginx:stable
kubectl rollout undo deployment/web
kubectl scale deployment/web --replicas=5
kubectl autoscale deployment web --min=2 --max=10 --cpu=60%

1 line became about 30. They buy you 3 copies that the scheduler tries to spread across machines, a cloud load balancer in front of them, and a rollout you can undo. If you need the rest of the commands, the kubectl cheat sheet lists them by task.

Docker Compose vs Kubernetes: 1 Host vs a Cluster

"Docker for development, Kubernetes for production" is what half the internet tells you. Docker disagrees: "Compose supports production deployments on single hosts." I agree with Docker. A single server running Compose is a fine production setup for a product with 1 team and a tolerance for a few minutes of downtime.

What Compose gives you in production:

  • Restart policies: restart: unless-stopped brings a container back after a crash or a daemon restart
  • Healthchecks: Docker marks a container healthy or unhealthy. It does not restart an unhealthy one by itself
  • Override files: docker compose -f compose.yaml -f compose.production.yaml up -d
  • Remote deploys: point DOCKER_HOST at the server

Where it ends:

  • Docker Compose / Kubernetes Machines: 1 host / A cluster of nodes
  • The host dies: Everything on it is down / Pods move to other nodes
  • Deploying a new version: Stops and recreates the container / Rolling update, old and new overlap
  • Rollback: Deploy the previous image again / kubectl rollout undo
  • Scaling: By hand, within 1 host / By hand or automatic, across nodes
  • Secrets: Environment variables and files / Secret objects (unencrypted in etcd by default in upstream Kubernetes)
  • Time to learn (my estimate): An afternoon / Months

The 2 rows that matter are the first 2. Compose = 1 host. When 1 host is no longer acceptable, you need a scheduler.

2 traps on the way out of Compose:

  • The deploy section (replicas, update_config, placement) is an optional part of the Compose Specification. A platform that does not support it ignores it, and the file is still valid
  • docker stack deploy, the Swarm command that takes a Compose file, reads only the legacy version 3 format. The current Compose Specification format "isn't compatible" with it

To move a Compose file to Kubernetes, start with a converter and then edit by hand: kompose convert (a Kubernetes project) or docker compose bridge convert (Docker Desktop 4.43.0 and later). (The converter writes the YAML. It does not write your readiness probes, your resource requests or your on-call rotation.)

Docker Swarm vs Kubernetes: The Smaller Cluster

Swarm mode is the clustering that ships inside Docker Engine. No extra software, 1 command to start: docker swarm init. It does more than its reputation says:

  • Replicated services that are rescheduled when a node fails

  • Rolling updates, 1 task at a time by default, with rollback

  • A routing mesh, so every node answers on a published port

  • Service discovery through built-in DNS

  • Secrets, encrypted in transit and at rest

  • Mutual TLS between nodes by default

  • Docker Swarm / Kubernetes Install: Built into Docker Engine / A managed service, or a project of its own

  • Control plane: 3 or 5 manager nodes. Docker recommends 7 at most / API server, etcd, scheduler, controllers

  • Scaling: You set the number of replicas / You set it, or an autoscaler does

  • Managed offering on AWS, Google Cloud, Azure: None / EKS, GKE, AKS

  • Ecosystem: Docker tooling / Helm, operators, Gateway API, most vendors

  • Commercial support: Mirantis / Every cloud and most vendors

Is Swarm dead? No. Classic Swarm, the 2014 standalone project, is archived, and Docker Engine dropped support for it in v23.0. Swarm mode is still in the Engine. Mirantis, which sells it commercially, wrote in July 2025: "Swarm will be fully supported through at least 2030 as part of Mirantis Kubernetes Engine 3."

The Swarm docs describe no autoscaler: you declare the number of tasks and the manager keeps it. My position: a Swarm that works today is no emergency. For a new platform I would not pick it, because the people, the tools and the cloud services you will hire and buy n

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.