How it works...
In our NGINX configuration (default.conf), we add the resolver directive (resolver 127.0.0.11 valid=1) that directs NGINX to use the built-in Docker DNS resolver. In order to distribute the load, setting the validity to 1 means any TTL is ignored and the result only stays valid for 1 second.
Then, we set the variable $backend to http://htestbackend:8000. The use of a variable ensures that it's evaluated each time in order to have the IP address updated.
Within Dockerfile, we have set the alias for the htest container to htestbackend. Once we call the scale command, this starts three additional containers. Although a unique name is allocated to each container (for example, loadbalancer_htest_1), the alias ensures that there's ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access