Scale Your Docker Containers with Docker Swarm

Extending the Hive

Promoting and Demoting Nodes

Docker allows you to promote and demote nodes, which comes in handy if a manager node becomes unavailable. For example, say your dockermanager needs to go down (for maintenance or some other reason), and you need to promote dockernode1 to a manager role. To do that, issue the command (on the manager):

docker node promote dockernode1

The command will inform you the node has been promoted (Figure 9).

Figure 9: A node has been promoted to manager.

If you want to demote a node (e.g., because you have the original dockermanager back up and functioning), you can demote dockernode1 back to regular node status (Figure 10) with the command (again, run from the manager):

docker node demote dockernode1
Figure 10: A node has been demoted back to standard node status.

You can enter

docker node promote dockernode1 dockernode2
docker node demote dockernode1 dockernode2

to promote/demote more than one node at a time, as well.

Leaving the Swarm

If, for whatever reason you have a node you want to pull out of the swarm, Docker has you covered. Head over to the node you want removed from the swarm and issue the command:

docker swarm leave

Once the node has left the swarm, enter (on the manager)

docker node rm dockernode2
docker node ls

to remove the node from the node list and verify that dockernode2 has, in fact, been removed (Figure 11). You can rejoin that node to the swarm with the same command you used before,

docker swarm join --token TOKEN 192.168.1.71:2377
Figure 11: dockernode2 is no longer on the list.

where TOKEN is the token issued when the manager was originally initialized.

At some point, you might need to force a manager to leave the swarm. To do this, enter:

docker swarm leave --force

At this point, your swarm is no longer functioning. To get it started again, start from the beginning to recreate your swarm.

Conclusion

With a few quick commands run on your Linux servers, you can scale containers with Docker Swarm to match the needs of your project or your business. Make use of three, four, five, 10, 20, … however many nodes it takes to give your containers the necessary horsepower and failover you need. With the help of a cluster of containers, your business can become more agile and enjoy serious uptime for services and apps.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus