Public Repository

Last pushed: 10 months ago
Short Description
Automated nginx proxy for Swarm Cluster
Full Description

Docker consul-template&nginx reverse proxy

Inspired by jwilder/nginx-proxy
This solution is intended to be used with Swarm Cluster
Consul-Template is used for listening Consul events and generating nginx config


To run it, you need to have next environment:

When requirements are satisfied, run this:

docker run -d \
    --privileged \
    --restart always \
    --name proxy \
    -p 80:80 \
    -e CONSUL_ADDR=$(docker-machine ip local-consul) \
    -e "constraint:type==public"
    --network public \

An image exposes as 80, as 443(https)

Environment variables

  • CONSUL_ADDR - ip address of Consul location
  • CONSUL_PORT - Consul port. By default 8500
  • IS_HTTPS - set as "1" if you want to use https. Also required CERT variable to be set
  • CERT - name of certificate. For instance, if is set, it will try to use /etc/nginx/certs/ and /etc/nginx/certs/ And of course you need to volume them or COPY before run

Running services

version: "2"
        image: nginx
            - 80
            - 'SERVICE_80_NAME=web/app'
            - 'SERVICE_80_TAGS="Name":"app.local"'
            - 'constraint:type==app'
            - public
        external: true

Running a service, there are some points which need to consider:

  • You should declare service ports which are needed to be proxy reversed
  • Each Docker-Compose service port is a separate service for Consul, so use SERVICE_$PORT prefix
  • SERVICE_80_NAME - consul service name declaration. Should have web/ prefix
  • SERVICE_80_TAGS - consul service tags.
    This solution is used to declare JSON options. Currently only Name supported which is needed for server domain definition


If you any ideas or PR, I would be happy to disscuss it! :)

Docker Pull Command

Comments (0)