Dynamic reverse proxy/load balancer for microservices running in a Docker network, based on nginx.
557
Dynamic reverse proxy and load balancer for microservices running in a Docker network, based on nginx.
You have n webservers running in host1..hostn in containers.
You want to have a reverse proxy running in gateway that load balances requests
to all these webserver containers.
The load-balancer is based on a Lua script that runs in the nginx process and queries periodically (every second) the DNS server about the service name. As long as your DNS server has up-to-date information about your containers, any container that appears with that name will be immediately available as an upstream server in nginx, and containers being stopped or dying will be immediately removed from this pool.
host* machines as you usually do
(docs)
(we will use the proxy
in this example):host1$ weave launch --init-peer-count n
host1$ eval $(weave env)
weave connect,
with Weave Discovery, etc)webservers. In this example, we use a minimal webserver
that listens on port 8080:host1$ docker run -p 8080:8080 --rm -ti --name webserver adejonge/helloworld
Launch as many webservers as you want, but all registered with the
same hostname (webserver) and listening on the same port.
gateway$ weave launch
gateway$ eval $(weave env)
gateway$ docker run -p 80:80 inercia/docker-nginx-dns 80:webserver:8080
You could expose and load-balance more services by adding them to the command line. For example:
gateway$ docker run -p 80:80 inercia/docker-nginx-dns 80:webserver:8080 81:graphite:8081
When used with Weave,
weave.local)
and you must not include it (eg, webserver is ok, webserver.weave.local
is not)Content type
Image
Digest
sha256:ce7959fdc…
Size
104.1 MB
Last updated
almost 11 years ago
docker pull inercia/docker-nginx-dns