Public | Automated Build

Last pushed: 2 years ago
Short Description
Short description is empty for this repo.
Full Description

Docker Easy Load Balancer

Experimental automagic load balancing for Docker web apps in less than 100 lines of bash.

Initial setup

On Ubuntu 14.04 hosts, you'll need to install libnss-resolver
and run:

apt-get install dnsmasq
echo "nameserver" | sudo tee -a /etc/resolver/

I suppose you are able to do something similiar when using Macs + Vagrant
/ boot2docker but I don't own a Mac to put the pieces
together, LMK if you know how to make this work over there and I'll update the docs

Try it

Launch the load balancer and DNS server:

git clone
cd docker-easy-lb

And verify if things are working:

# Is DNS working?
$ ping

PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=64 time=0.035 ms
64 bytes from icmp_seq=2 ttl=64 time=0.072 ms
64 bytes from icmp_seq=3 ttl=64 time=0.150 ms

# Can we reach the load balancer?
$ curl

    <title>404 - No application configured for this subdomain</title>

# Lets start a web server exposing the 3000 port
$ docker run -d --name hello -h hello -p 3000 ubuntu:14.04 python3 -m 'http.server' 3000

# And verify that the app has been addded to the load balancer
$ curl

<meta http-equiv="Content-Type" content="text/html; charset=ascii">
<title>Directory listing for /</title>
<h1>Directory listing for /</h1>

# Don't forget to clean up
$ docker rm -f hello

How does it work?

When the launch-host script gets run, it will start a dnsmasq server
on your machine pointing any address under * to a fgrehm/easy-lb
container that has the Docker socket /var/run/docker.sock bind mounted inside it. From
there it will use supervisord to kick off Redis +
Hipache + a "service" that will
register a Docker events listener
that responsible for registering / deregistering containers that
expose a port normally used by web apps.

It does not depend on any other tool apart from Docker and dnsmasq itself but it
plays really well with devstep, fig
and basically anything that creates Docker containers that is able to expose the
following ports:

  • 80
  • 3000
  • 4000
  • 4567
  • 5000
  • 8080
  • 9000
  • 9292


For some reason that I don't know yet the DNS / load balancer combo stopped
working every now and then during the early days of this project when a container
got removed. Even my Chrome browser crashed sometimes when the dnsmasq started

When that happens I first try restarting the dnsmasq server launched by the
launch-host script and if it still doesn't work I run:

sudo dpkg-reconfigure ubuntu14-libnss-resolver
docker rm -f easy-lb

If it still doesn't make things work please create an issue with as much information
as possible on how to consistently reproduce your problem.


  • Configurable domains
  • Register existing containers when bringing the load balancer up
  • Create a small app that lists configured apps from
  • Redirect to list of configured apps in case an invalid domain is accessed
  • Provide an example of an init script
  • Create an entrypoint that performs some validation before starting supervisord
  • Clean up / document code
  • Try to setup dnsmasq as part of the load balancer container


Docker Pull Command
Source Repository