Docker vs Kubernetes is a slightly misleading comparison, because they solve different problems. Docker packages your application and its dependencies into a container image and runs it on a machine. Kubernetes takes many containers across many machines and keeps them running, scaled, networked, and updated. You usually build with Docker-compatible tooling and run at scale with Kubernetes.
This article explains what each tool actually does, how they fit together, and how to tell whether your project needs Kubernetes yet.
What is Docker?
Docker is a platform for building and running containers. A container is a process isolated by operating system features such as namespaces and cgroups, running from a filesystem image that includes everything the application needs: runtime, libraries, and code. Unlike a virtual machine, it shares the host kernel, so it starts quickly and uses fewer resources. The containers guide covers the underlying concepts.
The core Docker workflow has three steps:
- Write a
Dockerfiledescribing how to build the image. - Build the image and push it to a registry.
- Run containers from that image anywhere a container runtime exists.
# Dockerfile for a small Node.js service
FROM node:22-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:22-alpine
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app/package*.json ./
RUN npm ci --omit=dev
COPY --from=build /app/dist ./dist
USER node
EXPOSE 3000
CMD ["node", "dist/server.js"]
The multi-stage build keeps build tools out of the final image, and running as a non-root user is a sensible security default. Docker also ships Docker Compose, which runs several containers together on one host, which is handy for local development with a database and cache.
What is Kubernetes?
Kubernetes is a container orchestrator. You describe the desired state of your system, such as "run three replicas of this image, expose them on port 80, and restart any that fail", and Kubernetes continuously works to make reality match that description.
Key building blocks:
- Pod: the smallest deployable unit, one or more containers sharing a network namespace.
- Deployment: manages a set of identical pods and handles rolling updates and rollbacks.
- Service: a stable network name and virtual IP that load-balances across pods.
- Ingress or Gateway: routes external HTTP traffic into services.
- ConfigMap and Secret: inject configuration and credentials without rebuilding images.
- Horizontal Pod Autoscaler: adds or removes pods based on metrics like CPU usage.
apiVersion: apps/v1
kind: Deployment
metadata:
name: orders-api
spec:
replicas: 3
selector:
matchLabels:
app: orders-api
template:
metadata:
labels:
app: orders-api
spec:
containers:
- name: orders-api
image: registry.example.com/orders-api:1.4.2
ports:
- containerPort: 3000
resources:
requests:
cpu: 250m
memory: 256Mi
limits:
memory: 512Mi
readinessProbe:
httpGet:
path: /healthz
port: 3000
---
apiVersion: v1
kind: Service
metadata:
name: orders-api
spec:
selector:
app: orders-api
ports:
- port: 80
targetPort: 3000
The Deployment keeps three healthy replicas running, and the readiness probe ensures traffic only reaches pods that are ready. The Service gives other workloads a stable name, orders-api, to call. The Kubernetes guide goes further into the control plane and scheduling.
How do Docker and Kubernetes work together?
Docker builds the artifact; Kubernetes runs it. A typical pipeline looks like this:
- CI builds a container image from your
Dockerfile. - The image is tagged and pushed to a registry.
- A deployment step updates the image tag in a Kubernetes manifest.
- Kubernetes pulls the image to its nodes and rolls out new pods gradually.
One detail often confuses people: modern Kubernetes does not use the Docker daemon to run containers. It talks to runtimes like containerd or CRI-O through the Container Runtime Interface. Images built with Docker still work, because they follow the OCI image standard that these runtimes understand.
Docker vs Kubernetes: key differences
| Aspect | Docker | Kubernetes |
|---|---|---|
| Primary job | Build and run containers | Orchestrate containers across a cluster |
| Scope | Single host (Compose for multi-container) | Many nodes |
| Scaling | Manual | Declarative and automatic |
| Self-healing | Basic restart policies | Reschedules failed pods onto healthy nodes |
| Networking | Host-level bridge networks | Cluster-wide service discovery and load balancing |
| Rolling updates | Not built in for single containers | Built in with rollback |
| Learning curve | Low | High |
| Best fit | Local dev, single-server apps, CI | Multi-service production workloads |
Docker Swarm, Compose, and other alternatives
Kubernetes is not the only way to run containers in production.
- Docker Compose works well for local development and simple single-server deployments.
- Docker Swarm offers lightweight orchestration with less complexity, though its ecosystem is smaller.
- Managed container services from cloud providers run containers without you managing a cluster at all.
- Managed Kubernetes services handle the control plane for you, which removes a large part of the operational burden.
The broader category is covered in the container orchestration guide.
When do you need Kubernetes?
Kubernetes earns its complexity when several of these are true:
- You run many services that need to find and talk to each other.
- Traffic varies and you need automatic scaling.
- You need zero-downtime deploys and quick rollbacks across services.
- Multiple teams deploy independently onto shared infrastructure.
If you have one or two services, a small team, and steady traffic, a managed container platform or a single VM with Compose is often simpler and cheaper to operate. Kubernetes adds concepts, YAML, networking layers, and upgrades that someone has to own. That trade-off is closely tied to architecture choices; see Microservices vs Monolith.
Key takeaways
- Docker packages and runs containers; Kubernetes orchestrates them across many machines.
- They are complementary, not competing: images built with Docker run on Kubernetes.
- Kubernetes uses containerd or CRI-O under the hood and runs any OCI-compliant image.
- Deployments, Services, and probes give you scaling, discovery, and self-healing.
- Adopt Kubernetes when orchestration problems are real, not by default.
Frequently asked questions
Can Kubernetes run without Docker?
Yes. Kubernetes uses container runtimes such as containerd or CRI-O and no longer depends on the Docker daemon. Images built with Docker still run because they follow the OCI image format.
Should I learn Docker or Kubernetes first?
Learn Docker first. Understanding images, containers, layers, and networking on a single host makes Kubernetes concepts like pods and services much easier to grasp.
Is Docker Compose enough for production?
It can be for small, single-server applications with modest availability needs. It does not provide multi-node scheduling, automatic failover, or built-in rolling updates, so larger systems usually outgrow it.
Is Kubernetes overkill for small projects?
Often, yes. For a handful of services with steady traffic, managed container platforms or simple VMs are easier to run. Kubernetes pays off as the number of services, teams, and scaling needs grows.