Kubernetes and Docker: What’s the difference?

Docker helps you create and run containers. Kubernetes manages them while you sleep.

Hundreds of tools seem to be shouting for your time and attention, and they don’t come much bigger and louder than Docker and Kubernetes. But what does Kubernetes do, that Docker does not? And what’s the real relationship between these two container-loving open source projects? Let’s find out.

Cardboard boxes and a captain's hat, depicting Docker containers and Kubernetes

Today we’re going to answer a common question amongst developers, DevOps newbies, IT architects – and in fact thousands of people – who are all asking:

“What’s the difference between Docker and Kubernetes?”

To answer this question, we’ll need to understand what each of these DevOps tools do, and when you might use them.

But first! If you want the quick summary, then here are the key facts you should know:

Summary

  • Docker is a company which provides a set of tools for building and sharing container images, and running containers at both small and large scale.

  • Kubernetes is a community open source project which manages container-based applications that are running on a cluster of servers.

  • You can use Docker without Kubernetes… and you can use Kubernetes without Docker!

  • Docker and Kubernetes aren’t competitors – they are two technologies which complement each other very well.

What is Docker?

The name ‘Docker’ means a few different things, which muddles the water a little! It’s a company, it’s a suite of tools, and it’s also a command, docker. So what exactly is Docker?

Docker is a company that makes a set of open source tools which make it easier to package and run applications in containers.

So the next question is – what is a container?

What is a container?

A container is a way to package and run an application, that surrounds it with a virtual wall, which isolates it from other applications on the computer.

By having this wall, an application, and all of its dependencies, such as libraries and configuration files, are strictly separated from the other applications running on the system.

This can make container-based applications much more portable, and easier to deploy and upgrade.

Container-based applications are also very easy to share, because they are usually published to a registry, which gives you the ability to find and run other people’s container images.

Dirk Merkel1 describes it like this:

Docker promises the ability to package applications and their dependencies into lightweight containers that move easily between different [Linux distributions], start up quickly and are isolated from each other.

So containers are:

  • Isolated… meaning it won’t interfere with other programs running on your computer, and

  • Consistent… meaning that every time you run a Docker container, it runs the same way, even on a different system.

  • Portable… meaning that a container can be stopped, moved to another computer, and started again, and it will run the same way.

With Docker’s container tools, you can create and share container images, run containers on your laptop or server, and even manage containers running on multiple servers, with Docker’s Swarm mode.

Let’s look a bit more about the features of Docker.

Docker features and tools

In Linux, the technology to create containers and containerised apps has existed for a while. But it was a little esoteric and required a lot of knowledge to use.

Docker made it far easier for developers to understand and use container technology, by creating some useful features, like:

  • Docker Engine – a command line tool (docker) which creates and runs containers on your computer

  • The Docker container image format – for creating and sharing container images, which later became an open standard

  • The Dockerfile – a language that describes how to build container images

  • Docker Hub – an online registry for publishing and sharing container images over the internet

  • Docker Compose – a lightweight way to share container setup instructions

  • Docker Swarm mode – a tool for managing containers running on multiple servers

Getting started with Docker

The easiest way to start using Docker is to install Docker Desktop, which bundles all of these tools into a program for Windows or Mac. Or, if you’re a little more familiar with the command-line, you can install Docker Engine directly into a virtual machine.

So, once you’ve installed Docker Desktop, what might you use Docker for?

What can you do with Docker?

There are lots of things that you can do with Docker:

  • Create container images (also called Docker images) for your applications - with docker build and a Dockerfile
Using Docker to create and publish container images

Using Docker to create and publish container images

Source: Tutorial Works

  • Run your own container images using Docker Engine

  • Share images with coworkers or other teams, by pushing them to a private image registry

  • Share images on the internet by pushing them to Docker Hub (a public image registry)

  • Run third-party containers such as databases, using images pulled from Docker Hub

  • Run multi-container applications with Docker Compose

In addition to these useful developer features, there’s also Docker Swarm mode, which is a utility for managing a cluster of Docker instances. Swarm lets you manage containers running on many different servers.

Now we’ve seen what Docker is, let’s take a look at Kubernetes.


What is Kubernetes?

If docker run is the way to run containers on your laptop, then Kubernetes is a robot that runs docker run on dozens, or hundreds, of servers for you.

Kubernetes turns a set of servers into a complete, private cloud.

Kubernetes is server-side software for managing containers.

Kubernetes automates all of the time-consuming tasks like creating containers and placing them on servers, configuring containers, checking container health, and controlling access to shared resources like memory and CPU. This puts it in a category of software called container orchestration tools.

Kubernetes does similar things to Docker Swarm, but there are a few differences, which you’ll see in the comparison table further below.

Kubernetes abstracts away the details of your servers, and instead provides you with a standard API that lets you deploy software onto a cluster. Under the hood, Kubernetes manages all of the servers in the cluster, and decides where to place containers, and how to connect them together.

So when you’re using Kubernetes, you don’t deploy your container-based app to a specific ‘server’. You describe your workload (your application), and Kubernetes decides where it should pull the container image and start the container.

What are the alternatives to Kubernetes?

Docker Swarm mode, Hashicorp Nomad, Apache Mesos and AWS’s Elastic Container Service are all container orchestration tools and are alternatives to Kubernetes.

Kubernetes features and tools

Kubernetes provides a set of objects called “primitives”. These primitives are like building blocks for creating apps, in the same way as you might build a model from Lego bricks. Some of Kubernetes’ primitives that you might have heard of include: Pods, Services and Deployments.

Kubernetes comes with these features:

  • Container scheduling – intelligently figuring out where to place containers, based on how busy each server is.

  • Container management – starting, stopping and restarting containers.

  • Auto-scaling containers – starting more containers when needed. For example: if an app is suddenly experiencing high traffic (e.g. on Black Friday), Kubernetes can start more containers to handle the load. It can also stop those containers afterwards, so you’re not using resources which you don’t need.

  • Networking – Creating and managing networks that allow containers to communicate with each other, and to load balance traffic across several instances of your app. (You could do this yourself, but when you’re running 1,000s of containers it gets really tough!)

  • Storage – managing access to disk, for those containers that need to write files

  • Logs and monitoring – gathering logs from containers and monitoring containers’ health

  • Security – establishing common rules and enforcing security restrictions on containers

Plus, Kubernetes is very extensible. You can change the way the networking layer works; you can connect your Kubernetes cluster to your cloud account so it can request more resources if needed; you can even use Kubernetes to manage virtual machines alongside containers if you want.

If you want to know a little more about Kubernetes, try Linux Foundation’s Introduction to Kubernetes course (it’s free).

Things you can do with Kubernetes

Once you’ve got a Kubernetes cluster up and running, what do you actually do with it? Why do people use Kubernetes?

With access to a Kubernetes cluster, you can:

  • Deploy your own container-based applications

  • Deploy third-party container-based applications from a public registry, like databases or web applications

  • Connect your apps to each other – e.g. so that your back-end API can talk to a database, or connect many containers together into an architecture of microservices

  • Upgrade applications by stopping existing containers and starting new ones with the updated software

  • Gather metrics on your apps – e.g. memory usage, CPU usage, and so on.

  • Automate tasks – e.g. automatically start more containers when your app is busy, or automatically restart containers if they crash

Kubernetes is popular because it standardised all of these things. We’ve been doing things like networking and log management for a long time, but now there is a standard way to implement them.


Comparing Docker and Kubernetes

Now that we’ve seen what Docker and Kubernetes are all about, what are the differences between them?

We can’t compare Docker and Kubernetes directly because they are two very different things. There are many different tools under the “Docker” name, and Kubernetes is a single project. But if you’re still unsure of the difference, we can probably say:

  • Docker is a set of tools for building and running containers, on your laptop, or on a bunch of servers.

  • Docker Compose is a tool for running multi-container applications on your laptop.

  • Docker Swarm is Docker’s tool for managing containers on a cluster of server, using the Docker Engine.

  • Kubernetes is a tool for deploying and managing containers on a cluster of servers, running any compatible container runtime, or even virtual machines.

Differences between Docker Swarm and Kubernetes

Here’s a table which compares the different features and of Docker Compose, Docker Swarm and Kubernetes:

Docker Compose Docker Swarm mode Kubernetes
Manages a group of containers on a single host Manages a cluster of instances of Docker Engine Manages a cluster of hosts running any compatible container runtime
Comes with Docker Desktop Built into Docker Engine Standalone project, not connected with Docker (but can be installed with Docker Desktop)
Works with Docker Engine Works with Docker Engine Works with any compatible container runtime
Manage with docker-compose Manage with docker swarm Manage with kubectl
.. .. Integration with cloud providers like AWS
No auto-scaling No auto-scaling Containers can be automatically scaled when they need more resources
A single product from Docker Inc. A single product from Docker Inc. A neutral project, with many different distributions available, like vanilla Kubernetes, OpenShift, VMware Tanzu, k3s, microk8s

Frequently Asked Questions

Which should you learn first, Docker or Kubernetes?

If you’re planning to work with Kubernetes, you should probably get comfortable using Docker first. Learning Docker will teach you the fundamentals of containers, like how to create an image, and how to run containers, and add storage and environment variables.

After that, you will find it easier to understand Kubernetes concepts like Pods and PersistentVolumes.

Which should you adopt, Docker or Kubernetes?

Both, seriously! You can use Docker for building your container images on your laptop, and then run your containers on a Kubernetes cluster.

Or, if you prefer, you can use Docker Swarm to orchestrate your containers instead of Kubernetes.

Wrapping it up

In this article we’ve seen that Docker and Kubernetes are two big tools for creating and running containers.

Dive into Docker on your laptop if you want to learn how to build and run containers. Then move onto Kubernetes to orchestrate your containers, and run them in production!

Want to learn more? The Containers Fundamentals course will teach you how to install, spin up, manage and troubleshoot containers.

Tom Donohue

By Tom Donohue, Editor | Twitter | LinkedIn

Tom is the founder of Tutorial Works. He’s an engineer and open source advocate. He uses the blog as a vehicle for sharing tutorials, writing about technology and talking about himself in the third person. His very first computer was an Acorn Electron.

Join the discussion

Got some thoughts on what you've just read? Want to know what other people think? Or is there anything technically wrong with the article? (We'd love to know so that we can correct it!) Join the conversation and leave a comment.

Comments are moderated.