The Docker Engine 1.12 includes a new feature known as swarm mode which allows the native management of a cluster of Docker Engines. This cluster of Docker Engines or nodes is known as a swarm. Swarm mode allows you to orchestrate services across all the nodes in a swarm. This is useful for the scaling, load balancing, distribution and availability of your services.
This tutorial will use Ansible to create 3 swarm nodes that correspond to the examples used in the docker tutorial. After running the playbook you will have access to three hosts exactly as described in the tutorial. A cleanup playbook is provided to remove all resources when you have completed the tutorial.
This tutorial assumes a number of things:
Firstly you need to install ansible as shown at Using Ansible.
When ansible is installed you should change directory to the example-playbooks/docker-swarm-mode directory within the catalystcloud-ansible git checkout.
$ cd example-playbooks/docker-swarm-mode
We can now run the create-swarm-hosts.yaml playbook to create the swarm:
$ ansible-playbook --extra-vars "ssh_public_key=$HOME/.ssh/id_rsa.pub" create-swarm-hosts.yaml
After this playbook successfully completes you are ready to complete the tutorial. As described in the tutorial setup instructions it provides:
Start the tutorial with the Create a swarm section. For example the first two commands are:
$ ssh manager1 $ docker swarm init --advertise-addr 192.168.99.100 Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager. To add a worker to this swarm, run the following command: docker swarm join \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ 192.168.99.100:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
The tutorial uses docker-machine ssh, you should omit docker-machine from the command as we did not create these nodes using docker machine. If you would prefer to use docker machine to setup the nodes you can follow the tutorial at Using Docker Machine on the Catalyst Cloud.
When you have completed the tutorial you can remove the swarm and its associated resources by running the remove-swarm-hosts.yaml playbook:
$ ansible-playbook remove-swarm-hosts.yaml