<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1194005000700189&amp;ev=PageView&amp;noscript=1">

From Vizuri's Experts

How to: Docker Swarm on CentOS in Azure step by step  part 3 of 3


If you are coming here from part 2 of the series you will recognize the setup here.

step 2-final -1.jpg

Our current status at the end of part 2  is we have 3 nodes running CentOS and Docker in Azure . For the final part of the series we will configure Swarm and configure a "service" and test it.


Step 1: SSH/Putty into node-1 and initialize Swarm

docker swarm init

 Take note of the token that is displayed after you run the init command

step 3-1.jpg


Step 2: Investigate your new Swarm 

You now have a Swarm with a single node. As it is the first and only node  it is the "Leader Manager" in that is is the the final word on all Swarm level configurations.  Find some information on your new Swarm.

docker info

step swarm is  active .jpg


step swarm active .jpg

Step 3: Add "worker nodes" to the Swarm

From the command line on the leader manager node-1 run the command "docker swarm join-token worker". Copy and paste the resulting text to your node-2 and node-3.

docker swarm join-token worker


step 3-d.jpg


 After you have run the command on both node-2 and node-3, go back to leader manager node 1 and run the command 

docker node ls

You will notice that the manager leader is still node 1 . You have now joined the other 2 nodes as workers.If you were to join or promote nodes as a manager they would join as a non-leader manager. Any additional non-leader managers have the ability to take over to be the leader manager in the event leader manager becomes unavailable. A non-leader manager will be instantly elected to leader manager if the current leader manager becomes unavailable for any reason.




part 3-h.jpg


Step 4: Create a Nginx "service" 

You now have a working Swarm and lets put it to good use. On your leader manager node 1 run the command

docker service create --replicas 3 --name nginx --publish 8080:80 nginx

step 3-4a.jpg



This will create one nginx container on each available node. In our current  configuration, the leader manager can also run containers. The default distribution configuration is to spread containers over each of the nodes.Run the command below to see more information on the newly launched service.

docker serivce ls

step 3-4b.jpg

Step 5: Connect to your default Nginx page


What is running on the each of the containers is a simple web server with a default landing page that should be able to access publicly.To do this we will need a few things.First, find out the port that is serving the web page from on the host ( not the container ) we can see that it is 8080.


Open the Azure console and from all resources Icon, search for "nsg" you will see one security group for each of your nodes.

step 3-nsg.jpg open the node-1 network security group (docker-node-1-nsg) and go to inbound rules and click the plus sign to add a new rule 


step 4 nsg 2.jpg


Add an inbound rule that allows port 8080 on the host to be accessed from the public internet. Save the rule.


step 4-nsg3.jpg


Repeat adding this rule for  node-2 and node-3.


Now we can connect on the Public IP ( the same IP you are ssh-ing on )  and the ports that we know is 8080

so open a browser to <public-ip>:8080

 setp 3 -e .jpg

you now have a working web server scaled across the swarm, you should be able to get the Nginx welcome page on all 3 nodes IP and port 8080.


To remove all of this simply delete the Resource Group

step 3 f .jpg


step 3 -h.jpg


I hope you have enjoyed this post and were able to take away some new skills. To become an expert in Docker sign up for one of our awesome classes today!

Brian Keyes

A former Vizuri systems engineer with more than twenty years of experience, Brian Keyes provided authority on subjects including VMware, storage, networking, and security. Interested in this post? Connect with our team of experts by