When automating the provisioning of new nodes to a swarm, you need to know what the right join token is for the swarm as well as the advertised address of the manager. You can find this out by running the following commands on any of the existing manager nodes:
# grab the ipaddress:port of the manager (second last line minus the whitespace) export MANAGER_ADDRESS=$(docker swarm join-token worker | tail -n 2 | tr -d '[[:space:]]') # grab the manager and worker token export MANAGER_TOKEN=$(docker swarm join-token manager -q) export WORKER_TOKEN=$(docker swarm join-token worker -q)
The -q option outputs only the token. Without this option you get the full command for registering to a swarm.
Then on newly provisioned nodes, you can join the swarm using.
docker swarm join --token $WORKER_TOKEN $MANAGER_ADDRESS