We get in touch with how to use services on Swarm by starting with a simple sample: Deploy and scale Nginx.
To make this chapter self-sufficient and useful for developers who are reading it as a stand-alone chapter. Let's quickly create a minimal Swarm Mode architecture locally, made of one manager and three workers:
We spawn up four Docker hosts:
for i in seq 3; do docker-machine create -d virtualbox node- $i; done
We then take control of
node-1
, which we elect as our static manager, and initialize it on a Swarm:eval $(docker-machine env node-1) docker swarm init --advertise-addr 192.168.99.100
Docker generates a token, for us, to join our three workers. So we just copy-paste that output to iterate through the other three workers to join them to the nodes:
for i in 2 3 4; do docker-machine ssh node-$i sudo docker swarm join \ --token SWMTKN-1- 4d13l0cf5ipq7e4x5ax2akalds8j1zm6lye8knnb0ba9wftymn- 9odd9z4gfu4d09z2iu0r2361v...