From 9c93efaef93e07ae8e2a050390cc410d08c4eb17 Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Sun, 12 Jun 2016 13:11:45 -0600 Subject: [PATCH 1/3] Fix template error when /etc/nginx/certs does not exist --- nginx.tmpl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nginx.tmpl b/nginx.tmpl index 855e90d..4716b75 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -112,11 +112,13 @@ upstream {{ $host }} { {{ $certName := (first (groupByKeys $containers "Env.CERT_NAME")) }} {{/* Get the best matching cert by name for the vhost. */}} +{{ $vhostCert := "" }} +{{ if exists "/etc/nginx/certs" }} {{ $vhostCert := (closest (dir "/etc/nginx/certs") (printf "%s.crt" $host))}} - -{{/* vhostCert is actually a filename so remove any suffixes since they are added later */}} -{{ $vhostCert := replace $vhostCert ".crt" "" -1 }} -{{ $vhostCert := replace $vhostCert ".key" "" -1 }} + {{/* vhostCert is actually a filename so remove any suffixes since they are added later */}} + {{ $vhostCert := replace $vhostCert ".crt" "" -1 }} + {{ $vhostCert := replace $vhostCert ".key" "" -1 }} +{{ end }} {{/* Use the cert specifid on the container or fallback to the best vhost match */}} {{ $cert := (coalesce $certName $vhostCert) }} From b325dad98d4c62f9267579e12d4f335cf5dfef25 Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Sun, 12 Jun 2016 13:54:48 -0600 Subject: [PATCH 2/3] Remove -only-exposed from Procfile --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index 8547156..0fa56e7 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ nginx: nginx -dockergen: docker-gen -watch -only-exposed -notify "nginx -s reload" /app/nginx.tmpl /etc/nginx/conf.d/default.conf +dockergen: docker-gen -watch -notify "nginx -s reload" /app/nginx.tmpl /etc/nginx/conf.d/default.conf From fdf93cafba28c2a110a1ec32472b4bce237551e3 Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Sun, 12 Jun 2016 13:55:18 -0600 Subject: [PATCH 3/3] Add docker-compose.yml v2 example --- README.md | 26 ++++++++++++++++++++++++++ docker-compose.yml | 15 +++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 docker-compose.yml diff --git a/README.md b/README.md index 6f93a19..93ea560 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,32 @@ The containers being proxied must [expose](https://docs.docker.com/reference/run Provided your DNS is setup to forward foo.bar.com to the a host running nginx-proxy, the request will be routed to a container with the VIRTUAL_HOST env var set. +### Docker Compose + +```yaml +version: '2' +services: + nginx-proxy: + image: jwilder/nginx-proxy + container_name: nginx-proxy + ports: + - "80:80" + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + + whoami: + image: jwilder/whoami + container_name: whoami + environment: + - VIRTUAL_HOST=whoami.local +``` + +```shell +$ docker-compose up +$ curl -H "Host: whoami.local" localhost +I''m 5b129ab83266 +``` + ### Multiple Ports If your container exposes multiple ports, nginx-proxy will default to the service running on port 80. If you need to specify a different port, you can set a VIRTUAL_PORT env var to select a different one. If your container only exposes one port and it has a VIRTUAL_HOST env var set, that port will be selected. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..044f022 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +version: '2' +services: + nginx-proxy: + image: jwilder/nginx-proxy + container_name: nginx-proxy + ports: + - "80:80" + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + + whoami: + image: jwilder/whoami + environment: + - VIRTUAL_HOST=whoami.local +