prepend the generated nginx config file with a warning when $CurrentContainer is null
One case where `$CurrentContainer` ends up being `null` is when you use the template from a separated container having no exposed port and you call the docker-gen process with the `-only-exposed` option.
----
Example compose file to reproduce the case:
version: '2'
networks:
default: {}
volumes:
nginx_conf: {}
nginx_certs: {}
services:
nginx:
image: nginx
container_name: nginx
volumes:
- nginx_conf:/etc/nginx/conf.d
- nginx_certs:/etc/nginx/certs
dockergen:
image: jwilder/docker-gen
command: -notify-sighup nginx -only-exposed -watch /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
volumes_from:
- nginx
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- nginx_conf:/etc/nginx/conf.d
- nginx_certs:/etc/nginx/certs
- ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl
This commit is contained in:
parent
6554a1cf28
commit
58f71d7907
1 changed files with 17 additions and 0 deletions
17
nginx.tmpl
17
nginx.tmpl
|
|
@ -1,5 +1,22 @@
|
|||
{{ $CurrentContainer := where $ "ID" .Docker.CurrentContainerID | first }}
|
||||
|
||||
{{/* When docker-gen is running from a separated container and with the
|
||||
-only-exposed (or -only-published) option, the template won't be provided
|
||||
with the current (docker-gen) container info, making $currentContainer `null`.
|
||||
*/}}
|
||||
{{ if not $CurrentContainer }}
|
||||
###############################################################################
|
||||
# #
|
||||
# Are you using using jwilder/nginx-proxy's nginx.tmpl with docker-gen #
|
||||
# running in a separated container? #
|
||||
# #
|
||||
# Consider removing the docker-gen `-only-exposed` option and make sure #
|
||||
# the docker-gen container has access to the same networks as the nginx #
|
||||
# container. #
|
||||
# #
|
||||
###############################################################################
|
||||
{{ end }}
|
||||
|
||||
{{ define "upstream" }}
|
||||
{{ if .Address }}
|
||||
{{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue