Difficulty: intermediate
Estimated Time: 10-15 minutes

In this scenario, you will learn how to use Docker Compose and Stacks to deploy services on a Docker Swarm Mode cluster. The new Stacks features were added as part of the Docker Compose version 3 (v3) improvements.

Environment

The environment has been configured with two Docker machines that can communicate with each over TCP.

Don’t stop now! The next scenario will take about 20 minutes to complete. You can pause and come back at any time.

Deploy Swarm Services with Compose v3

Step 1 of 3

Step 1 - Initialise Swarm Mode

By default, Docker works as an isolated single-node. All containers are only deployed onto the engine. Swarm Mode turns it into a multi-host cluster-aware engine.

Task: Initialise Swarm Mode

To use the secrets functionality, Docker has to be in "Swarm Mode". This is enabled via docker swarm init

Join Swarm Mode

Execute the command below on the second host to add it as a worker to the cluster.

token=$(docker -H [[HOST_IP]]:2345 swarm join-token -q worker) && docker swarm join [[HOST_IP]]:2377 --token $token

Terminal Host 2