From ca6b32365440d9132093afd3f4ae9b15319b8c80 Mon Sep 17 00:00:00 2001 From: mitja Date: Thu, 6 Apr 2017 10:55:38 +0200 Subject: [PATCH] Added DEFAULT_IP env variable --- nginx.tmpl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/nginx.tmpl b/nginx.tmpl index a5b1d32..9d8ba9c 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -9,11 +9,11 @@ {{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}} {{ else if .Network }} # {{ .Container.Name }} - server {{ .Network.IP }}:{{ .Address.Port }}; + server {{ .Network }}:{{ .Address.Port }}; {{ end }} {{ else if .Network }} # {{ .Container.Name }} - server {{ .Network.IP }} down; + server {{ .Network }} down; {{ end }} {{ end }} @@ -110,16 +110,17 @@ upstream {{ $upstream_name }} { {{ range $containerNetwork := $container.Networks }} {{ if eq $knownNetwork.Name $containerNetwork.Name }} ## Can be connect with "{{ $containerNetwork.Name }}" network - + + {{ $containerNetworkIp := or $container.Env.DEFAULT_IP $containerNetwork.IP }} {{/* If only 1 port exposed, use that */}} {{ if eq $addrLen 1 }} {{ $address := index $container.Addresses 0 }} - {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }} + {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetworkIp) }} {{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var, falling back to standard web port 80 */}} {{ else }} {{ $port := coalesce $container.Env.VIRTUAL_PORT "80" }} {{ $address := where $container.Addresses "Port" $port | first }} - {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }} + {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetworkIp) }} {{ end }} {{ end }} {{ end }}