This guide will show you how to setup a docker swarm. Assuming you already have docker installed.

Setting up docker swarm

For setting up a swarm, you need at least 3 vm’s which will contain:

  • A manager Node (or more)
  • And worker nodes

Setting up a manager node

Log in to your Manager vm and run following command:

docker swarm init –advertise-addr <MANAGER-IP>

The other nodes in the swarm must be able to access the manager at the IP address. So be aware of Firewall restrictions, iptables,…

You will get a output like this:

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.

You can add multiple Manager nodes this way:

[me@portainermgr01prod ~]$ docker swarm join-token manager To add a manager to this swarm, run the following command: docker swarm join --token SWMTKN-1-2vqxciwl7q5nmtv7vy6jbeh8ilo29u7bs1eko24ztazn8n87a7-d201wmooe8hd8ll19klmhyt0v 10.136.23.11:2377

Run the “docker swarm join –token SWMTKN-1-2vqxciwl7q5nmtv7vy6jbeh8ilo29u7bs1eko24ztazn8n87a7-d201wmooe8hd8ll19klmhyt0v 10.136.23.11:2377” on the other nodes you want to join as a manager.

Setting up the worker nodes

Log in to your worker nodes and run the command you got from the output of the manager node:

docker swarm join \ --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \ 192.168.99.100:2377

If you don’t have the command available, you can run the following command on a manager node to retrieve the join command for a worker:

docker swarm join-token worker

After you have run the commands on your workers, you can check the status of your workers using following command on the MANAGER node:

[me@portainermgr01prod ~]$ docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION onh1rgb37cbgsl2sx6zwlcrlh portainer01prod Ready Active 18.09.7 tyw38g3pl9q2km1kwi4mk0brd portainer02prod Ready Active 18.09.7 uu6sh1gk87bxkughvrwdezber portainer03prod Ready Active 18.09.7 vaq6nqm92vv1raq6pfdzl7y1s * portainermgr01prod Ready Active Leader 18.09.7 7d9g9cx5ce0wn5x114o1m0qz3 portainermgr02prod Ready Active Reachable 18.09.7 scpw73v2ei49udcg36oy2ltrf portainermgr03prod Ready Active Reachable 18.09.7 [me@portainermgr01prod ~]$