Chapter 2 of 47 · Foundations

Docker vs Kubernetes

People often ask "Docker or Kubernetes?" It is the wrong question. They do different jobs, and in production you usually use both.

Two different jobs

Docker builds and runs containers. One command, one container, on the machine you are typing on.

Docker runs a container that holds your applicationDockerContainerYour application
DockerKubernetes
Main jobBuild images and run containersKeep many containers running as you asked
Works onOne machineA group of machines (a cluster)
You say"Run this container now""I want 3 of these, always"
Container crashesIt stays down unless you set a restart policy on that one hostIt is replaced, on any healthy machine

How they fit together

They are not competitors. A common production setup uses Docker to make the image and Kubernetes to run it:

From code to KubernetesYour code is built by Docker into an image. The image runs as a container. Kubernetes manages the containers.Your code+ Dockerfiledocker buildDocker imagemicro-postsContainerthe image, runningKubernetesmanages themyou writeDocker makesKubernetes runs and watches
The image you build with Docker is exactly what Kubernetes runs.
Small print. Inside a cluster, Kubernetes usually starts containers with a runtime called containerd rather than Docker itself. You do not need to care: an image built with Docker runs the same way.

Who does it?

For each job, pick the tool that is responsible for it.

Recap

Docker vs Kubernetes: common questions

Does Kubernetes replace Docker?

No. Docker builds the image and Kubernetes runs and manages the containers made from it. A common setup uses both.