I'm using Docker to deploy lots of micro services behind a reverse proxy. I would like to load balance my micro services based on DNS queries and also allow for automated failover and rebalancing once the proxy has started up.

I'm looking for a proxy server which supports load balancing between the returned servers from a DNS query. So for example test.local returns servers,, and I would like to load balance traffic between them and do some standard reverse proxy rerouting stuff.

Nginx does the DNS query at startup but doesn't do the DNS query periodically and honour the TTL unless you have the Nginx Plus, which is expensive. If I restart my proxy periodically as the servers change then it might work but that would throw bad requests and wouldn't be a good solution.

I've looked to see if this can be done with Apache but I've not found anything.

Any help setting this up would be greatly appreciated as it's the last piece of the puzzle I need to get my servers fault tolerant.

  • 1
    And this is one of many reasons why DNS-based load balancing should be avoided if possible. There are plenty of superior ways to accomplish this. – EEAA Dec 6 '16 at 14:02
  • I am actually not looking for DNS based load balancing. I am load balancing via a reverse proxy server but I want my reverse proxy server to detect the ip address and quantity of containers in a pool by using the DNS system. Nginx offers this service but only on their paid version which is too expensive for my use case. – robwithhair Dec 9 '16 at 14:17
  • Are you positive that nginx doesn't do what you want? I was under the impression it actually does this. See nginx.org/en/docs/http/ngx_http_core_module.html#resolver for details. – Håkan Lindqvist Mar 2 '17 at 8:47

You have clearly reached a level of complexity that you won't be able to handle using plain docker any more.

At this point you need to start using a higher level abstraction tool to manage your resources. The obvious choices are:

You don't provide enough details about the underlying platform that would help in choosing one over the other. My personal preference is Kubernetes, because I can abstract from pretty much any platform, and I can abstract even further to provide higher level capabilities using OpenShift or Tectonic.

Kubernetes operates on containers using the pod as the minimum abstraction unit. This allows a Kubernetes cluster to orchestrate and direct traffic to pods based on different probes.

In practice, this means you can perform deployments of new containers without downtime, have Kubernetes create new containers should the probe return failure, and even rollback the deployment (blue/green strategy).

This barely scratches the surface of what Kubernetes can do. If you are interested, the project has a very good documentation.

  • I am already using Docker Swarm actually. I am not having issues with the routing from ports or the docker environment. I am looking for a good load balancer. Obviously I don't want to be updating the proxy server config every time a container get's rebalanced, so I'm looking for a proxy server which can get it's config from a DNS lookup, as Docker Swarm-mode already has the functionality to advertise service containers via DNS lookup. Nginx offers this but only on the paid version and that is too expensive for our use case. – robwithhair Dec 9 '16 at 14:16
  • OpenShift Origin manages this out of the box. You might want yo take a look at the online documentation. It uses HAProxy to load balance, the amount and health of the backend containers is checked constantly to ensure requests areonly proxied downstream to healthy containers. – dawud Dec 10 '16 at 16:57
  • Ooo, that looks interesting. Thanks, I'll have a look. – robwithhair Dec 13 '16 at 14:23

Check out this github repo which might be able to meet your requirement: https://github.com/StalkR/dns-reverse-proxy

Install go package, create Debian package, install:

$ go get -u github.com/miekg/dns
$ go get -u github.com/StalkR/dns-reverse-proxy
$ cd $GOPATH/src/github.com/StalkR/dns-reverse-proxy
$ fakeroot debian/rules clean binary
$ sudo dpkg -i ../dns-reverse-proxy_1-1_amd64.deb

Configure in /etc/default/dns-reverse-proxy and start with /etc/init.d/dns-reverse-proxy start.

  • While this matches the title, reading the actual question it sounds like they are actually asking for an HTTP reverse proxy (with some special requirements), not a DNS reverse proxy. – Håkan Lindqvist Mar 2 '17 at 8:50
  • No this isn't quite what I'm looking for but thanks for the link – robwithhair May 16 '17 at 16:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.