I was trying to set up a cluster with docker swarm. However, I am a bit confused about how is docker-machine with swarm options different from initialising a swarm manager on one host and joining as workers from other hosts.
Here is an example for my question:
docker-machine with swarm options
docker-machine create --driver virtualbox --swarm --swarm-master --virtualbox-hostonly-cidr "10.0.0.1/24" node1
docker-machine create --driver virtualbox --swarm --swarm-discovery "token://..." --virtualbox-hostonly-cidr "10.0.0.1/24" node2
docker-machine create --driver virtualbox --swarm --swarm-discovery "token://..." --virtualbox-hostonly-cidr "10.0.0.1/24" node3
join a manager node as worker nodes
docker-machine create --driver virtualbox --virtualbox-hostonly-cidr "10.0.0.1/24" node1
docker-machine create --driver virtualbox --virtualbox-hostonly-cidr "10.0.0.1/24" node2
docker-machine create --driver virtualbox --virtualbox-hostonly-cidr "10.0.0.1/24" node3
eval $(docker-machine env node1)
docker swarm init
eval $(docker-machine env node2)
docker swarm join --token <token> <node1_IP>
eval $(docker-machine env node3)
docker swarm join --token <token> <node1_IP>
The first method you used is from old docker version when SWARM need to have a discovery key/value store setup
docker-machine create --driver virtualbox --swarm --swarm-master --virtualbox-hostonly-cidr "10.0.0.1/24" node1
docker-machine create --driver virtualbox --swarm --swarm-discovery "token://..." --virtualbox-hostonly-cidr "10.0.0.1/24" node2
docker-machine create --driver virtualbox --swarm --swarm-discovery "token://..." --virtualbox-hostonly-cidr "10.0.0.1/24" node3
The second method you had used is the Swarm mode
To use Docker in swarm mode, install Docker 1.12.0 or later
This was introduced in Docker 1.12.0. This is the method you should be using now as all new commands like docker service
, docker stack
require swarm mode. They won't work on the old one