Public | Automated Build

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


This is a simple NGINX load balancer that automatically reconfigures itself according to running containers.

How it works

  1. nginx-lb search for running containers and group them by application name*
  2. Configures an NGINX virtual host for every app load balancing between its Docker instances.
  3. Monitors Docker for events
  4. Repeat setup when an event is found
  • An application name is detected by splitting containers name with _ and discarting the last bit. The application name is used as the app domain inside NGINX. A few examples of valid container names: myapp. myapp. dev.myapp.com_1. For those examples the app name would be, and, respectively. Note that has two instances to be load balanced to.


nginx-lb is an automated Docker image. Pull it with:

docker pull rochacon/nginx-lb


  • DOCKER_HOST - HTTP address of the Docker host. e.g
  • PORTS - Comma separated list of containers ports to monitor. e.g 80,8080


Launch nginx-lb

docker run -d -p 80:80 --name nginx-lb \
    -v /var/run/docker.sock:/var/run/docker.sock:ro \
    -e PORTS=80,8080 \

Use the DOCKER_HOST environment to monitor a Docker daemon listening on TCP.

Launch some app instances

docker run -p 80 --name myapp.example.com_1 myimage
docker run -p 80 --name myapp.example.com_2 myimage
docker run -p 80 --name myapp.example.com_3 myimage

Hit application


Checking current setup

docker exec nginx-lb cat /etc/nginx/nginx.conf



Docker Pull Command
Source Repository