Docker Compose with Docker Swarm
We have described how to use Docker Swarm in order to deploy a service, which in turn runs multiple containers from the given Docker image. On the other hand, there is Docker Compose, which provides a method to define the dependencies between containers and enables scaling containers, but everything is done within one Docker host. How do we merge both technologies so that we can specify the docker-compose.yml
file and automatically distribute the containers on a cluster? Luckily, there is Docker Stack.
Introducing Docker Stack
Docker Stack is a method to run multiple-linked containers on a Swarm cluster. To understand better how it links Docker Compose with Docker Swarm, let's take a look at the following figure:

Docker Swarm orchestrates which container is run on which physical machine. The containers, however, don't have any dependencies between themselves, so in order for them to communicate, we would need to link them manually. Docker Compose, in contrast...