This is where it may get confusing. If a service is the same as running container then a stack is running a collection of services like you would launch multiple containers using Docker Compose. In fact, you can launch a stack using a Docker Compose file, with a few additions.
Let's look at launching our Cluster application again. You can find the Docker Compose file we are going to be using in the repo in the /bootcamp/chapter04/cluster/
folder, before we go through the contents of the docker-compose.yml
file, let's launch the stack. To do this run the following command:
docker stack deploy --compose-file=docker-compose.yml cluster
You should get confirmation that the network for the stack has been created along with the service. You can list the services launched by the stack by running:
docker stack ls
And then check on the tasks within the service by running:
docker stack ps cluster
You may be surprised to see that service has launched its tasks on swarm02
and swarm03...