liveBook · Manning

Load balancing

As explained in Learn Docker in a Month of Lunches, Second Edition

Load balancing is the distribution of requests or traffic across multiple service instances.

Load balancing spreads traffic across multiple service instances. Docker Compose provides a simple form by returning every container IP address for a service through DNS. section 7.3

Understand the practical limits of this approach:

  • The application performs the DNS lookup and decides how to process multiple addresses. section 7.3
  • Some applications use only the first returned address, while Docker changes the ordering between lookups to spread traffic. section 7.3

Scale a service

Run `docker compose up -d --scale iotd=3`, then execute `nslookup iotd` inside the web container. The lookup returns three addresses, one for each service container.

docker compose up -d --scale iotd=3
# for Linux containers:
docker container exec -it image-of-the-day-image-gallery-1 sh
# for Windows containers:
docker container exec -it image-of-the-day-image-gallery-1 cmd
# now inside the container session run:
nslookup accesslog
exit

Use the command listing to scale the service and inspect its DNS responses from a Linux or Windows container shell. section 7.3

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Demonstrates scaling and DNS inspection, but stops short of application-side response-selection logic.
Examples
Uses three scaled iotd containers, nslookup output, and container removal followed by restoration.
What it assumes
Assumes familiarity with Docker Compose services, containers, shells, and basic DNS lookup commands.
What you can do after
Operate Docker Compose scaling and inspect returned service addresses from inside a running container.
How it connects
Connects Docker Compose, containers, service discovery, DNS, and application-level address selection.

Also explained in

Compare how 14 books explain load balancing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.