<commit_before># nginx-lb

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


## How it works

0. `nginx-lb` search for running containers and group them by application name*
0. Configures an NGINX virtual host for every app load balancing between its Docker instances.
0. Monitors Docker for events
0. Repeat setup when an event is found

* An application name is detected by splitting containers name with _ and discarting the last bit. Examples of container names: `myapp_1` `myapp_2` `mywebapp_web_1`. For those examples the app name would be `myapp`, `myapp` and `mywebapp_web`, respectively. Note that `myapp` has two instances to be load balanced to.


## Install

`nginx-lb` is an [automated Docker image](https://registry.hub.docker.com/u/rochacon/nginx-lb). Pull it with:

    docker pull rochacon/nginx-lb


## Configuration

- `DOCKER_HOST` - HTTP address of the Docker host. e.g `http://172.16.17.32:2375`
- `DOMAIN` - Base domain to set applications virtualhosts. e.g `lo.rochacon.me`
- `PORTS` - Comma separated list of containers ports to monitor. e.g 80,8080


## Running

    docker run -d -p 80:80 --name nginx-lb \
        -e PORTS=80,8080 \
        -e DOCKER_HOST=http://172.17.42.1:2375 \
        -e DOMAIN=local.mybasedomain.com \
        rochacon/nginx-lb


## Checking current setup

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


## License
<commit_msg>readme: Better Usage section<commit_after># nginx-lb

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


## How it works

0. `nginx-lb` search for running containers and group them by application name*
0. Configures an NGINX virtual host for every app load balancing between its Docker instances.
0. Monitors Docker for events
0. Repeat setup when an event is found

* An application name is detected by splitting containers name with _ and discarting the last bit. Examples of container names: `myapp_1` `myapp_2` `mywebapp_web_1`. For those examples the app name would be `myapp`, `myapp` and `mywebapp_web`, respectively. Note that `myapp` has two instances to be load balanced to.


## Install

`nginx-lb` is an [automated Docker image](https://registry.hub.docker.com/u/rochacon/nginx-lb). Pull it with:

    docker pull rochacon/nginx-lb


## Configuration

- `DOCKER_HOST` - HTTP address of the Docker host. e.g `http://172.16.17.32:2375`
- `DOMAIN` - Base domain to set applications virtualhosts. e.g `lo.rochacon.me`
- `PORTS` - Comma separated list of containers ports to monitor. e.g 80,8080


## Usage

Launch `nginx-lb`


    docker run -d -p 80:80 --name nginx-lb \
        -e PORTS=80,8080 \
        -e DOCKER_HOST=http://172.17.42.1:2375 \
        -e DOMAIN=server0.example.com \
        rochacon/nginx-lb


Launch some app instances


	docker run -p 80 --name myapp_1 myimage
	docker run -p 80 --name myapp_2 myimage
	docker run -p 80 --name myapp_3 myimage


Hit application

	
	curl myapp.server0.example.com


## Checking current setup

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


## License

{'fraction_non_alphanumeric': 0.09149072296865003, 'fraction_numerical': 0.03422904670505438, 'mean_word_length': 3.3856942496493687, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '547752', 'n_tokens_mistral': 1096, 'n_tokens_neox': 982, 'n_words': 380}