Example
# Create the nodes
# In a real world scenario we would use at least 3 managers to cover the fail of one manager.
docker-machine create -d virtualbox manager
docker-machine create -d virtualbox worker1
# Create the swarm
# It is possible to define a port for the *advertise-addr* and *listen-addr*, if none is defined the default port 2377 will be used.
docker-machine ssh manager \
docker swarm init \
--advertise-addr $(docker-machine ip manager)
--listen-addr $(docker-machine ip manager)
# Extract the Tokens for joining the Swarm
# There are 2 different Tokens for joining the swarm.
MANAGER_TOKEN=$(docker-machine ssh manager docker swarm join-token manager --quiet)
WORKER_TOKEN=$(docker-machine ssh manager docker swarm join-token worker --quiet)
# Join a worker node with the worker token
docker-machine ssh worker1 \
docker swarm join \
--token $WORKER_TOKEN \
--listen-addr $(docker-machine ip worker1) \
$(docker-machine ip manager):2377