Jarle Aase

How to install Docker Swarm with docker-machine

bookmark 1 min read

Install Docker Swarm from a Linux host.

The host needs Docker and VirtualBox installed.

for i in 1 2 3; do  docker-machine create -d virtualbox node-$i; done;
eval $(docker-machine env node-1)
docker swarm init --advertise-addr $(docker-machine ip node-1)
for i in 2 3; do  docker-machine ssh node-$i docker swarm join --token $(docker swarm join-token -q worker) $(docker-machine ip node-1):2377; done;
docker node ls

And that's it!

To access the swarm, you can use docker commands on your local machine, because you ran "eval $(docker-machine env node-1)", which points the docker command to the docker engine instance on node-1 (which happens to be the swarm master node).

you can also ssh to the nodes:

docker-machine ssh node-1

To remove the setup

for i in 1 2 3; do  docker-machine rm -f node-$i; done;