Difficulty: intermediate
Estimated Time: 10-15 minutes

In this scenario, you will learn how to use Docker to load balance network traffic to different containers. With the introduction of Swarm Mode and Services, containers can now be logically grouped by a friendly name and port.

Requests to this name/port will be load balanced across all available containers in the cluster. This increases availability and the load distribution.

This functionality is provided as part of Swarm's routing mesh. Internally it's using the Linux IPVS, an in-kernel Layer 4 multi-protocol load balancer.

The environment has been configured with two Docker Hosts.

Don’t stop now! The next scenario will only take about 10 minutes to complete.

Load Balance and Service Discover in Swarm Mode

Step 1 of 4

Step 1 - Initialise Cluster

Before beginning, initialise Swarm Mode and add the second host to the cluster.

Click the commands below to execute them.

docker swarm init

docker swarm join [[HOST_IP]]:2377 --token $(docker -H [[HOST_IP]]:2345 swarm join-token -q worker)

Terminal Host 2