Docker vs Kubernetes: What Is the Difference?

Blog / Docker vs Kubernetes: What Is the Difference?
Docker vs Kubernetes: what actually is the difference between Docker and Kubernetes? This post explains exactly that.

How Docker Works

Docker is a tool for building and running applications in containers. It packages an application with everything it needs to run.

You write a configuration file called a Dockerfile. This file lists the exact operating system, dependencies and code your application needs.

Building this file gives you an image, which is a static snapshot of your application. Running that image gives you a container.

A Dockerfile is built into an image, and the image runs as a container
dockerfile
FROM node:20 WORKDIR /app COPY . . RUN npm install EXPOSE 8080 CMD ["npm", "start"]
Here is what each line does:
  • FROM node:20 starts from an image that already has Node installed.
  • WORKDIR /app works inside an /app folder.
  • COPY . . copies our code into the image.
  • RUN npm install installs the dependencies while the image is built.
  • EXPOSE 8080 says the app listens on port 8080.
  • CMD ["npm", "start"] is the command that starts the app when a container runs.

To create and start this application, you only need two commands. First you build the image, and then you run it.

bash
docker build -t my-app . docker run -p 8080:8080 my-app

docker build -t my-app . builds the image and names it my-app. docker run -p 8080:8080 my-app starts a container from that image and maps port 8080 on your machine to port 8080 in the container.

A container is simply an isolated running process on your machine.

The Single-Host Problem

Docker runs containers on one machine. If that machine crashes, the entire application goes down with it.

If user traffic grows past what that one server can handle, there is nowhere to put more containers. And someone has to restart failed containers and roll out new versions by hand.

So how do we solve these single-host limitations? This is exactly where Kubernetes comes in.

How Kubernetes Works

Kubernetes is a tool for running and managing containers at scale, often called a container orchestrator. It runs containers across a cluster of machines.

The control plane is the central system that decides what workloads should run and where they should be placed. The worker nodes are the physical or virtual machines that actually run the containers.

Containers run inside pods, which are the smallest deployable units that Kubernetes manages.

A Kubernetes cluster: the control plane decides what runs where, and each worker node runs a pod

You do not start these pods manually. Instead, you describe your desired state in a configuration file called a Deployment.

yaml
apiVersion: apps/v1 kind: Deployment metadata: name: my-app spec: replicas: 3 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: - name: my-app image: my-app:latest ports: - containerPort: 8080
Here is what each block does:
  • apiVersion and kind: Deployment say what type of Kubernetes object this file creates.
  • metadata gives the Deployment its name, my-app.
  • replicas: 3 says how many copies of the app to keep running.
  • selector and the template labels are how the Deployment knows which pods are its own. Every pod it creates gets the app: my-app label.
  • containers says what each pod runs: the image Docker built, listening on containerPort 8080.
Kubernetes reads this file and automatically keeps the cluster matching that desired state.

Self-Healing and Scaling

If a container crashes or a whole worker node fails, Kubernetes immediately notices the problem. It sees that the cluster no longer matches your desired state of three replicas.

It automatically provisions replacement pods on other healthy nodes to restore the balance.

To handle more traffic, you simply change the replica count in your file and Kubernetes adds more pods.

To route user traffic to all these moving pods, you create a Service. A Service gives the pods one stable network address and spreads incoming traffic evenly across them, acting as an internal load balancer.

How Docker and Kubernetes Work Together

They are not competitors. Docker builds the application image and pushes it to a central registry. Kubernetes then pulls that exact image and runs many copies of it across the cluster.

Docker builds the image and pushes it to a registry, and Kubernetes pulls it and runs copies on every node

Modern Kubernetes actually runs containers through a lightweight container runtime such as containerd, rather than the full Docker engine itself. However, it still runs the exact same standard images that Docker builds.

You use Docker to package the software, and Kubernetes to operate it at scale.

When You Need Kubernetes

Docker Compose is a tool that runs a few containers together on one single machine.

yaml
services: frontend: image: my-frontend ports: - "3000:3000" backend: image: my-app ports: - "8080:8080" db: image: postgres:16 environment: POSTGRES_PASSWORD: example

This file starts three containers together, a frontend, our my-app backend and a Postgres database, with one command: docker compose up

This simple approach is perfectly fine for local development, testing and small applications.

Kubernetes is a complex distributed system, but it is worth the operational effort when your application needs specific production capabilities. You should use Kubernetes when you need:
  • Many machines working together to handle workloads
  • High availability during unexpected hardware failures
  • Automatic scaling to match unpredictable heavy traffic
  • Zero-downtime rollouts for deploying new software versions

Recap

Feature

Docker

Kubernetes

What it is

A containerization platform

A container orchestration platform

What it manages

Individual containers

Clusters of machines and pods

Scope

A single host machine

Multiple worker nodes

Main job

Building and running images

Scaling and healing applications

  • What it is: Docker is a containerization platform. Kubernetes is a container orchestration platform.
  • What it manages: Docker manages individual containers. Kubernetes manages clusters of machines and the pods running on them.
  • Scope: Docker works on a single host machine. Kubernetes works across multiple worker nodes.
  • Main job: Docker builds and runs images. Kubernetes scales and heals your application.

About TechPrep

Never walk into a technical interview unprepared again. TechPrep empowers software engineers to stop guessing and start getting offers. We provide the exact questions asked by tech companies across Data Structures & Algorithms, System Design, Low-Level Design & AI coding rounds. Don't leave your career up to chance. Join thousands of engineers who have successfully navigated the tech hiring maze and landed roles at top tech companies.