Published:

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.

1for i in 1 2 3; do  docker-machine create -d virtualbox node-$i; done;
2eval $(docker-machine env node-1)
3docker swarm init --advertise-addr $(docker-machine ip node-1)
4for 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;
5docker node ls
6

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:

1docker-machine ssh node-1

To remove the setup

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