├── .dockerignore ├── .gitignore ├── Dockerfile ├── README.md ├── handler.sh ├── hipache.json ├── launch-host ├── no-app-app ├── index.html └── server ├── service.sh └── supervisord.conf /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | supervisor-logs 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | logs 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Based on https://raw.githubusercontent.com/hipache/hipache/master/Dockerfile 2 | 3 | # Latest Ubuntu LTS 4 | FROM ubuntu:14.04 5 | 6 | # Install some stuff 7 | RUN apt-get -y update && \ 8 | apt-get -y install supervisor nodejs npm redis-server && \ 9 | npm install -g hipache 10 | 11 | # Download the docker CLI 12 | RUN apt-get install -y curl && \ 13 | curl https://get.docker.io/builds/Linux/x86_64/docker-latest > /usr/bin/docker && \ 14 | chmod +x /usr/bin/docker 15 | 16 | # Download and install jq 17 | RUN curl http://stedolan.github.io/jq/download/linux64/jq > /usr/bin/jq && \ 18 | chmod +x /usr/bin/jq 19 | 20 | # Install the static web server 21 | RUN npm install -g node-static 22 | 23 | # Add our supervisor configs 24 | ADD ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf 25 | 26 | # Add our custom hipache configs 27 | ADD hipache.json /usr/local/lib/node_modules/hipache/config/config.json 28 | 29 | # Our docker events handler 30 | ADD ./service.sh /usr/bin/auto-lb 31 | ADD ./handler.sh /usr/bin/auto-lb-handler 32 | 33 | # The dummy app that handles unknown domains 34 | ADD ./no-app-app /no-app-app 35 | 36 | # Expose hipache 37 | EXPOSE 80 38 | 39 | # Start supervisor 40 | CMD ["supervisord", "-n"] 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker Easy Load Balancer 2 | 3 | Experimental _automagic_ load balancing for Docker web apps in less than 100 lines of bash. 4 | 5 |  6 | 7 | ## Initial setup 8 | 9 | On Ubuntu 14.04 hosts, you'll need to install [libnss-resolver](https://github.com/azukiapp/libnss-resolver#installing) 10 | and run: 11 | 12 | ```sh 13 | apt-get install dnsmasq 14 | echo "nameserver 127.0.0.1:5353" | sudo tee -a /etc/resolver/docker.dev 15 | ``` 16 | 17 | _I suppose you are able to do something similiar when using Macs + [Vagrant](http://www.vagrantup.com/) 18 | / [boot2docker](http://boot2docker.io/) but I don't own a Mac to put the pieces 19 | together, LMK if you know how to make this work over there and I'll update the docs 20 | accordingly_ 21 | 22 | ## Try it 23 | 24 | Launch the load balancer and DNS server: 25 | 26 | ```sh 27 | git clone https://github.com/fgrehm/docker-easy-lb.git 28 | cd docker-easy-lb 29 | ./launch-host 30 | ``` 31 | 32 | And verify if things are working: 33 | 34 | ``` 35 | # Is DNS working? 36 | $ ping hello.docker.dev 37 | 38 | PING hello.docker.dev (172.17.0.175) 56(84) bytes of data. 39 | 64 bytes from 172.17.0.175: icmp_seq=1 ttl=64 time=0.035 ms 40 | 64 bytes from 172.17.0.175: icmp_seq=2 ttl=64 time=0.072 ms 41 | 64 bytes from 172.17.0.175: icmp_seq=3 ttl=64 time=0.150 ms 42 | ^C 43 | 44 | # Can we reach the load balancer? 45 | $ curl hello.docker.dev 46 | 47 | 48 |
49 |