Creating a Swarm Cluster

Walisson de Deus Casonatto
Quick Mobile Labs
Published in
1 min readSep 27, 2016

On Docker 1.12 its even easier to create your own Docker Swarm Cluster. On this guide, we will use this new advantage to quickly create a local cluster with docker-machine and Virtualbox.

Requirements:

  • Docker Machine
  • Virtual Box
  • Docker 1.12+

First of all, we need to create our machines:

docker-machine create -d virtualbox manager
docker-machine create -d virtualbox worker-01
docker-machine create -d virtualbox worker-02

After creating them, we will configure our terminal to send commands to the manager machine and start the swarm mode:

eval $(docker-machine env manager)docker swarm init

A virtual machine has two network interfaces, because of it Swarm is going to ask you witch one you want to use. Choose eth1, because this one u can access from the other machines:

docker swarm init --advertise-addr {eth1 ip}

After it, Swarm will return a command line. This command let you join other nodes to the cluster:

docker swarm join \
-token {some token}\
{manager ip}:2377

We just need to swap between the other nodes and run the join command:

eval $(docker-machine env worker-01)
docker swarm join -token {some token} {manager ip}:2377
eval $(docker-machine env worker-02)
docker swarm join -token {some token} {manager ip}:2377

Nice! Now we have 3 nodes on our cluster.

You can check it by running:

docker node list

Cool, right?

We also have a interesting material about how use some Docker Swarm’s features like Service Discovery. Check it out!

--

--