Added DEFAULT_IP env variable

This commit is contained in:
mitja 2017-04-06 10:55:38 +02:00
parent 619943ac1e
commit ca6b323654

View file

@ -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 }}