Docker Compose vs Docker Swarm vs Kubernetes?

Docker Compose vs Docker Swarm vs Kubernetes?

What are Docker Compose, Docker Swarm, and Kubernetes for exactly?

Docker Compose, Docker Swarm, and Kubernetes are tools for orchestrating container workloads. Orchestrating container workloads broadly means doing all the work to deploy software using containers.

When using tools like Docker Compose, Docker Swarm, and Kubernetes, you describe your desired deployment in a configuration file, and when you pass the configuration file to Docker Compose, Docker Swarm, or Kubernetes the tool makes all of the changes that are needed to produce the desired deployment.

For example, the following Docker Compose configuration will produce a deployment of Docker containers to provide a simple web application:

You could use the Docker command line interface (docker) to create networks, populate storage volumes, run containers, and do everything else to make the example web application available instead of using orchestration software. However, using tools like Docker Compose, Docker Swarm, and Kubernetes to orchestrate containers usually makes managing containers simpler, more repeatable, and more maintainable over the long term compared to issuing the commands yourself.

If you are going to run the same workload in Docker repeatedly, I recommend learning enough to use Docker Compose to make starting up and breaking down the workload easier.

How are Docker Compose, Docker Swarm, and Kubernetes actually different from one another then?

The main differences between Docker Compose, Docker Swarm, and Kubernetes are the scale at which the tool operates best and the problem the tool tries to solve

The difference of scale

Scale is the main difference between Docker Compose on one side and Docker Swarm and Kubernetes on the other. Docker Compose is only meant for running workloads in Docker containers on a single machine in a single instance of the Docker Engine service. Docker Compose cannot help run Docker containers across multiple machines. Docker Swarm and Kubernetes, in contrast, support deploying your workload across multiple hosts by default.

That is not to say Docker Compose is not useful. In fact, if you do not need to deploy your Docker containers across multiple machines then using Docker Compose can help you avoid unnecessary complexity and overhead from using Docker Swarm or Kubernetes.

Docker Compose is an excellent choice for deploying Docker containers on a single machine and can save you time and effort managing your workload compared to issuing Docker commands yourself.

The difference of problems to solve

At its core, Docker Compose is a tool for deploying workloads to Docker on a single machine in a more convenient, repeatable, maintainable fashion. Docker Compose focuses on solving the problem of deploying Docker containers and their required resources (that is, storage volumes, networks, etc.).

Docker Swarm and Kubernetes both focus on how to solve the problem of operating container workloads in production at large scale. Operating container workloads in production at large scale is a much more complex problem that covers deploying the containers, making updates to workloads without service outages, handling failures, providing ongoing information about running workloads, load cleaning, and other features for keeping services available. This means Docker Swarm and Kubernetes have to do much more than Docker Compose. Docker Swarm and Kubernetes both provide functionality to accomplish all of these parts of operating container workloads in production at scale and more, but there are key differences between them.

Docker Swarm is only for Docker Engine

First, Docker Swarm is for running containers using Docker Engine only, but Kubernetes supports running containers using Docker Engine or other software instead of Docker Engine. This means that if you use Docker Swarm you have to use Docker Engine to run your containers. That may be a problem for you if you prefer to use other software to run your containers.

Kubernetes and Docker Swarm have different service architectures

Second, Kubernetes and Docker Swarm have different architectures for running the services that make a Kubernetes cluster or Docker Swarm cluster. Kubernetes uses separate control plane and worker services, whereas all Docker Swarm cluster members can provide control plane services or worker services.

The Kubernetes control plane services keep track of the state of the Kubernetes cluster and any deployed workloads. The control plane services also dispatch changes to the workloads running on the clusters, and the worker services actually run your workloads.

With Docker Swarm, the same Docker Engine service can function as a manager (that is, control plane) service, as a worker service, or as both a manager service and worker service at the same time. Manager services keep track of the Docker Swarm cluster state and manage applying changes to the Docker Swarm cluster. Worker services actually run your Docker containers.

There are tradeoffs to each approach, but one is not necessarily always better than the other. You should consider how well each architecture suits your individual needs and capabilities. For example, if your tools are made to work with Kubernetes, you should probably use Kubernetes. If you are most comfortable and experienced with Docker, using Docker Swarm may be better than adopting an entirely new tool.

Docker Swarm and Kubernetes​ are two different ways of doing containers at large scale

The main thing you should ask yourself when considering Docker Compose, Docker Swarm, or Kubernetes is: what do you need today to help you manage your Docker containers? If you have a real need for features like autoscaling or are currently managing containers on tens, hundreds, or thousands of machines, you probably could benefit from using Docker Swarm or Kubernetes. If your workload consists of fewer than maybe 10 containers and runs on a few machines, Docker Compose may be good enough.

Docker Swarm and Kubernetes are great solutions for running large scale workloads, but they do not always work well for small scale solutions. In my experience, smaller teams working at smaller scale often struggle to manage the complexity solutions like Docker Swarm and Kubernetes introduce and see few or no improvements over using a simpler solution like Docker Compose.

Think about what your needs are for managing your Docker containers, and remember: you can always do something different.