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 \
dmitrovskiy/docker-nginx-consul-template:1.10.1-0.16.0-alpine
An image exposes as 80, as 443(https)
CONSUL_ADDR
- ip address of Consul locationCONSUL_PORT
- Consul port. By default 8500IS_HTTPS
- set as "1" if you want to use https. Also requiredCERT
variable to be setCERT
- name of certificate. For instance, iftest.com
is set, it will try to use/etc/nginx/certs/test.com.crt
and/etc/nginx/certs/test.com.key
. And of course you need to volume them or COPY before run
version: "2"
services:
app:
image: nginx
ports:
- 80
environment:
- 'SERVICE_80_NAME=web/app'
- 'SERVICE_80_TAGS="Name":"app.local"'
- 'constraint:type==app'
networks:
- public
networks:
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 haveweb/
prefixSERVICE_80_TAGS
- consul service tags. This solution is used to declare JSON options. Currently onlyName
supported which is needed for server domain definition
If you any ideas or PR, I would be happy to disscuss it! :)