In my previous post, Getting Started with Docker
Swarm,
I started a Docker Swarm on a single node and showed how to manage
services on it.
This time, I will start a two node Docker Swarm and go over commands
to manage multiple nodes, such as:
starting the Swarm
viewing Swarm status
joining the Swarm
obtaining join-tokens
and leaving the Swarm
Requirements
If you would like to follow along:
Install Virtualbox
Install Vagrant
Download this
Vagrantfile
to your local folder and modify this line:
to be:
Notes on Vagrantfile configuration
This makes two different virtualboxes, one named: manager, another
named: worker1.
With the way the Vagrantfile configuration, connects each virtualbox
to a private network with IP Addresses 192.168.100.10 and
192.168.100.11, for manager and worker1, respectively.
All actions taken on manager & worker1 are equivalent to working on
separate computers.
Boot the manager
Let’s start by creating the manager virtualbox by issuing command:
Now the manager is running. Confirm its status by:
Let’s go and configure manager for Swarm!
Start Swarm on manager
Let’s get into the manager box to start working with Docker Swarm!
Let’s check if Docker Swarm is running or not:
Good, now that means we can start Docker Swarm with command:
Save this output for worker1 to join manager as part of the swarm.
Lost join-token?
IF you ever need to get the worker join token again from the
manager, this would be the command:
You know, asking for a friend. ;-)
Current Swarm Status
Now that we have initialized a Swarm, how do we know its status? By
using the node command:
So far, there’s only the manager node on the swarm. Let’s fix that by
adding worker1 using the join-token (you printed a copy of that,
right?! If not, use the join-token command.
Start worker1
Just like with manager, let’s boot up worker1 and login:
Verify worker1’s status by:
Let’s get worker1 on manager’s swarm:
Join manager’s Swarm
With worker1 running, let’s use the worker join-token and connect to
the manager Swarm. Lost the join-token? Get it
again!
Tada~ Wasn’t that easy? But, how can we see workers in swarm? By
running node ls command on the manager
instance:
So, worker1 is officially part of the Swarm!
Leave Swarm
Now that worker1 is part of the Swarm, let’s leave it.
And the best way to check, use the node ls
command from manager:
Interesting, worker1 left the swarm, but manager just sees worker1’s
status as: Down.
Conclusion
This has been a review on how to work with multiple node Docker Swarm
commands such as:
starting the Swarm
from a manager node: sudo docker swarm init
obtaining worker join-token
from a manager node: sudo docker swarm join-token worker
viewing Swarm status
from a manager node: sudo docker node ls
joining the Swarm
use the Swarm join token, which is in the form: sudo docker swarm join ...
leaving the Swarm
from the leaving node: sudo docker swarm leave
This is just the start of managing multiple node Docker Swarm and I
will continue my explorations in future articles.