Cloud & DevOps

Docker vs Kubernetes: what each one does and when Kubernetes is needed

Team Nippysoft
• • 10 min read
Docker vs Kubernetes: what each one does and when Kubernetes is needed

Docker packages an application with everything it needs to start and runs it as a container on one machine. Kubernetes takes those ready-made packages and keeps them running across many machines: how many copies exist, where each one runs, how they find each other and what happens when one fails. They do not compete: Docker builds and runs, Kubernetes orchestrates.

What Docker is

Docker works with four pieces:

  • Image: the package with everything a container needs to start: operating system files, the language runtime, dependencies, code and settings. Once built, it never changes.
  • Container: an ordinary process on the machine that runs in isolation, started from an image.
  • Dockerfile: the recipe the image is built from.
  • Registry: the service that stores images and hands them out, such as Docker Hub.

A container is not a virtual machine. Every virtual machine boots its own operating system, kernel included; a container shares the kernel of the machine it runs on and starts like any other process. That is why a Linux container needs a Linux kernel: on macOS and Windows, Docker Desktop runs Linux containers inside a small Linux virtual machine.

The problem it solved

Without containers, an application depends on whatever is installed on each machine. The laptop, the continuous integration server and production can carry different versions of the runtime and the dependencies, and that is where "it works on my machine" comes from. Docker packages the application with everything it needs, so it runs the same way on every machine that has Docker. Solomon Hykes introduced it in March 2013, in a five-minute lightning talk at PyCon.

With a multi-stage build, the Dockerfile has several FROM instructions: one stage compiles and the final one copies only the result, so whatever was needed to compile never reaches production.

What Kubernetes is

Kubernetes is an open source platform for managing containerized workloads and services. A team describes what it wants, for example "three copies of this image, reachable under this name", and Kubernetes works to make what is running match that desired state. If a container fails, it restarts or replaces it; if a container does not answer the health check the team defined, Kubernetes kills it and sends it no traffic until it is ready. It does not compile code or build images, and its documentation says it is not a traditional, all-inclusive PaaS (platform as a service).

A Pod is the smallest unit Kubernetes deploys: one or more containers that share network and storage and run together. A node is a machine, physical or virtual, where Pods run. A cluster is a control plane plus one or more nodes. And on each node, the kubelet makes sure its Pods are running.

The problem that shows up with many containers

With one machine and docker run, whoever operates it has to work out by hand what happens if the container dies or the machine goes down, how to run three copies and spread traffic, how other services find them when their IPs change, how HTTP traffic gets in, how to grow with load and where configuration and secrets live without rebuilding the image. Kubernetes answers each question with an object:

NeedKubernetes object
N copies that get replaced when they dieDeployment, which creates the Pods through a ReplicaSet
A stable name for Pods that come and goService
Knowing whether a container is alive or readyProbes: liveness, readiness and startup
HTTP traffic from outsideIngress with an Ingress controller, or Gateway API
Growing with loadHorizontalPodAutoscaler (HPA)
Configuration and secretsConfigMap and Secret

Where it comes from

Kubernetes was born at Google, among engineers who knew Borg and Omega, two systems used inside the company, and who saw how popular Docker had made containers. The first commit reached GitHub on June 6, 2014, and version 1.0 shipped on July 21, 2015, when Google announced it would donate Kubernetes to the newly formed Cloud Native Computing Foundation (CNCF). As of November 2026, the stable version is 1.37 and the project maintains the 1.37, 1.36 and 1.35 branches.

Why "Docker vs Kubernetes" is the wrong question

The question mixes two layers: Docker produces the image and Kubernetes receives it to operate it. Kubernetes builds nothing, so it always needs an image made beforehand. Three comparisons do put things from the same level side by side.

Compose versus Kubernetes

Docker Compose defines a multi-container application in a YAML file and starts it with a single command, in production too: Docker's documentation says the easiest way to deploy is a single server. The difference is scope: Compose starts the services on one machine; Kubernetes spreads copies across many and replaces them when they fail.

Swarm versus Kubernetes

Swarm mode is built into Docker Engine and manages a cluster of Docker Engines with the same desired-state idea: a service sets replicas, network, storage and ports, and if a node becomes unavailable, Docker schedules its tasks on other nodes. Docker suggests it for scaling a Compose application. It is not Docker Classic Swarm, which is no longer actively developed. This is the direct comparison: two orchestrators.

What runs the containers on each node

On each node, the Kubernetes kubelet asks a runtime to start the containers, through CRI, the Kubernetes container runtime interface. The documentation lists containerd, CRI-O, Docker Engine and Mirantis Container Runtime. Up to version 1.23, Kubernetes shipped dockershim, a direct integration with Docker Engine; it was deprecated in 1.20 and removed from the kubelet in 1.24, released on May 3, 2022. Since then, using Docker Engine as the runtime requires cri-dockerd, an adapter that Mirantis and Docker committed to maintaining.

Kubernetes did not stop accepting Docker images: images built with docker build work the same with containerd or CRI-O.

The reason is a standard: images follow the specifications of the Open Container Initiative (OCI), which Docker, CoreOS and other companies launched on June 22, 2015, with three specifications: runtime, image and distribution. Docker donated its container format and runc to the OCI, and runc is today the default runtime underneath containerd (CRI-O has defaulted to crun since version 1.31). And since Docker Engine 29.0, on fresh installations, Docker's default image store is containerd's. The two tools share the OCI format and, when the node runs containerd, containerd and runc as well.

The full path, from code to scaling

An assumed case makes it concrete: the API of an online store that has to stay available and gets more traffic at some hours than at others.

The path from code to HPA: Docker builds and delivers the image, Kubernetes runs it and keeps it running Docker: builds and delivers the image Kubernetes: runs the image and keeps the desired state changes the Deployment's replicas handoff point Code the application Dockerfile the recipe Image immutable OCI package Registry stores and hands out Deployment which image, how many Pods kubelet + runtime Service stable name Ingress or Gateway HTTP ingress HPA scales with load 1. Code: the application the team writes 2. Dockerfile: the recipe; multi-stage separates compiling from running 3. Image: docker build creates it, immutable and in OCI format 4. Registry: stores the image and hands it to the cluster 5. Deployment: the desired state, which image and how many copies 6. Pods: the kubelet starts them with containerd or CRI-O 7. Service: a stable name and IP in front of the Pods 8. Ingress or Gateway: HTTP ingress, with a separate controller 9. HPA: more or fewer Pods depending on load, with Metrics Server Docker builds and delivers the image; Kubernetes runs it and keeps it running
StepWhat it isWho does it
1. CodeThe applicationThe team
2. DockerfileThe recipe; multi-stage separates compiling from runningDocker (BuildKit)
3. ImageAn immutable package in OCI formatdocker build
4. RegistryStores and hands out imagesDocker Hub, GHCR, ECR, ACR…
5. DeploymentThe desired state: which image and how many copiesKubernetes
6. Pods on the nodesThe containers that actually runkubelet with containerd or CRI-O
7. ServiceA stable name and IP in front of the PodsKubernetes
8. Ingress or GatewayHTTP traffic in from outsideA controller installed separately
9. HPAMore or fewer Pods depending on loadKubernetes with Metrics Server

The team writes the API and a multi-stage Dockerfile, builds the image and pushes it to a registry. The registry is the handoff point between Docker and Kubernetes. A Deployment asks for three copies, for example; the kubelet on each node starts the Pods. Because Pods are ephemeral and a new one comes with a different IP, the rest of the store calls a Service, and outside traffic comes in through an Ingress or through Gateway API.

What the team has to define

  • Probes: the liveness probe decides when to restart a container, the readiness probe when it is ready to accept traffic, and the startup probe covers boot. A badly implemented liveness probe can lead to cascading failures.
  • Requests: the CPU and memory each container reserves. The HPA computes CPU as a percentage of each container's request, not of the machine, and without a CPU request it does not scale on CPU. The metric is usually served by Metrics Server, installed separately. By default it checks every 15 seconds and, before scaling down, applies a 5-minute stabilization window. With an HPA, the Deployment should not set replicas: every time it is applied, it undoes what the HPA scaled.
  • Shutdown: a Pod being removed gets 30 seconds by default to finish. At the same time it starts shutting down, it is marked as terminating and not ready in the Service's EndpointSlices, without being removed right away, and load balancers stop sending it regular traffic. A preStop hook with the sleep action, stable since 1.34, delays the shutdown by the configured number of seconds; Kubernetes added it as a straightforward way to manage graceful shutdowns.

HTTP ingress in 2026

The Kubernetes documentation declares the Ingress API frozen: it will get no further changes, though there are no plans to remove it, and the project recommends Gateway API. On top of that, Kubernetes retired Ingress NGINX in March 2026: existing installations keep working, but they get no more releases or bug fixes, and the project's statement makes clear that none of the alternatives is a drop-in replacement.

Ingress, the API, is still part of Kubernetes; what was retired is Ingress NGINX, one of its controllers, which no longer gets security patches.

Configuration, secrets and Pod security

Configuration goes in a ConfigMap, which offers no secrecy or encryption and cannot exceed 1 MiB. Sensitive data goes in a Secret, which protects less than its name suggests.

By default, a Secret is stored unencrypted in etcd, the cluster's database: anyone with API access can read or change it, and anyone who can create Pods in a namespace (an isolated group of resources inside the cluster) can read every Secret in that namespace.

The Secret documentation asks for at least four steps: enable encryption at rest, grant access to Secrets through least-privilege RBAC, restrict which containers can see them and consider an external secret store.

For the Pod, the Restricted profile of the Pod Security Standards requires runAsNonRoot, allowPrivilegeEscalation: false, a seccomp profile (RuntimeDefault or Localhost) and drop: ALL on capabilities. The rest of cluster hardening is in Kubernetes security.

When Kubernetes is not needed

Kubernetes solves problems of many machines and many services, and the price is operating it: the ingress controller and Metrics Server are installed separately, probes and requests have to be designed, and Secrets need extra protection. No official source sets a threshold such as "from N services on", so what follows is judgment:

  • Compose is enough for one application, or a few, on one machine with no high-availability requirement.
  • Swarm fits when several machines are needed and the team already works with Docker and Compose, since it is built into Docker Engine.
  • A PaaS or a managed container service fits when the team does not want to operate infrastructure: it hands over the image and the platform runs it.
  • Kubernetes pays off with several machines and several services that need to scale or update without downtime, and a team that can operate it.

The same image serves all four cases, so starting with Compose does not close the door on Kubernetes.

Learning order

Docker comes first, because Kubernetes starts from an image that is already built. This order is judgment; each step uses the one before:

  1. Container and image.
  2. Multi-stage Dockerfile.
  3. Compose: several services on one machine.
  4. Pod, Deployment and Service.
  5. Probes and resources.
  6. ConfigMap and Secret, knowing what each one does not protect.
  7. Gateway API for new work, and Ingress to understand what already exists.
  8. HPA, which depends on the requests from step 5.
  9. Pod security.

Conclusion

Docker and Kubernetes are not alternatives: one leaves the image in the registry and the other picks it up from there. The useful comparison is Compose or Swarm versus Kubernetes, and it comes down to how many machines the service needs and who will operate the cluster. With one machine, Compose is enough. With several and a team, the path in this article works as a map for the first Deployment.

References

Subscribe

Get the latest posts delivered right to your inbox.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Comments

No comments yet. Be the first to share your thoughts!

Subscribed!

Registered! A confirmation link has been sent to your email address. If you don't see it, please check your spam folder.

Error

An error occurred. Please try again.

Full code