Difficulty: Beginner
Estimated Time: 10 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 will be load balanced across all available containers in the cluster. This increases availability and the load distribution.

This scenario explained advanced docker service concepts like replicas and rolling updates.

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

Advanced Docker Service

Step 1 of 5

Step 1 - Initialise Swarm

Turn single host Docker host into a Multi-host Docker Swarm Mode. Becomes Manager By default, Docker works as an isolated single-node. All containers are only deployed onto the engine. Swarm Mode turns it into a multi-host cluster-aware engine.

The first node to initialise the Swarm Mode becomes the manager. As new nodes join the cluster, they can adjust their roles between managers or workers.

Task: Create Swarm Mode Cluster

Swarm Mode is built into the Docker CLI. You can find an overview the possibility commands via docker swarm --help

The most important one is how to initialise Swarm Mode. Initialisation is done via init. docker swarm init

Task: Add Worker Node

With Swarm Mode enabled, it is possible to add additional nodes and issues commands across all of them. If nodes happen to disappear, for example, because of a crash, the containers which were running on those hosts will be automatically rescheduled onto other available nodes. The rescheduling ensures you do not lose capacity and provides high-availability.

Task

We first ask the manager what the token is via swarm join-token and join the cluster token=$(docker -H [[HOST_IP]]:2345 swarm join-token -q worker) && docker swarm join [[HOST_IP]]:2377 --token $token

Protip

You can view all nodes in the cluster using docker node ls

Terminal Host 2