Public | Automated Build

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


DockerHub Repository:


This repository contains a scripts for creating configurable load balancer Consul Key-Value store API with nginx and consul-template.



  • Run
docker run -d -p 80:80 \
    --link consul:consul \
    -e "CONSUL_KV_PREFIX=nginx" \
  • Custom nginx config

Inside the container there is a file config.json which contains default values for all of the configuration
options that are read by the consul template. When this container starts these default values are pre-loaded
into consul, so that when it comes to reading these values when the template is parsed, there are already default

However you can change these default values by providing your own config.json:

docker run -d -p 80:80 \
    -v /path/to/config.json:/config.json \
    --link consul:consul \
    -e "CONSUL_KV_PREFIX=nginx" \
  • Custom template
docker run -d -p 80:80 \
    -v $(pwd)/config.json:/config.json \
    -v /path/to/nginx.conf.ctmpl:/etc/nginx/nginx.conf.ctmpl \
    -e "CONSUL_KV_PREFIX=nginx" \
  • Dynamic configuration change via Consul API.
curl -X PUT -d "/var/log/nginx/error.log" http://consul_host:8500/v1/kv/nginx/error_log
  • Changing the consul hostname

By default this container tries to connect to a consul server running on localhost. If you want to specify a different
location for the consul server, set the CONSUL_PORT_8500_TCP_ADDR environmental variable. If you are linking this
container to the consul container then you should set the CONSUL_PORT_8500_TCP_ADDR variable to the alias of the
consul container:

docker run -d -p 80:80 \
    -v /path/to/config.json:/config.json \
    --link consul:consul \
    -e "CONSUL_KV_PREFIX=nginx" \
    -e "CONSUL_PORT_8500_TCP_ADDR=consul" \


This repository contains a example dockerize application build with vagrant machine.(Requires Vagrant and Ansible)

  • Setup VM and docker containers.
make install
  • Change configuration.
curl -X PUT -d "/var/log/nginx/error.log"
  • Ensure nginx conf is properly rewrited.
docker exec -it nodes_nginx_1 cat /etc/nginx/nginx.conf
  • Set tag to application upstream.
curl -X PUT -d "0.0.1"

This will set upstream of service named httpd to tagged with 0.0.1 containers. Service registration is automated by registrator.

  • If something goes wrong, restart all containers
make restart

How to

  • Consul data persistence
docker run -d -v /mnt:/data progrium/consul:latest -server -bootstrap -data-dir /data -ui-dir /ui
  • Set multiple value in same key
# Edit config.json
# Set JSON key-value pair as a Value.
"location": {
"proxy_set_header": "{\"X-Real-IP\": \"$remote_addr\", \"X-Forwarded-For\": \"$proxy_add_x_forwarded_for\", \"X-Forwarded-Proto\": \"$scheme\", \"Host\": \"$host\"}"

# Edit consul template file
{{ range $key, $pairs := tree "location" | byKey }}
  {{ range $pair := $pairs }}
    {{ range $key, $value := printf "location/%s"  $pair.Key | key | parseJSON }}
        {{ $key }}{{ value }}
    {{ end ]}
  {{ end }}
{{ end }}
  • Run with Host networking
docker run -d --net host -v $(pwd)/config.json:/config.json -e "CONSUL_KV_PREFIX=nginx" -e "CONSUL_PORT_8500_TCP_ADDR=CONSUL_HOST_IP" shufo/nginx-consul-template


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Docker Pull Command
Source Repository