diff --git a/volumes/proxy/templates/nginx-compose-v2.tmpl b/volumes/proxy/templates/nginx-compose-v2.tmpl index a48da6f..bc21d29 100644 --- a/volumes/proxy/templates/nginx-compose-v2.tmpl +++ b/volumes/proxy/templates/nginx-compose-v2.tmpl @@ -77,15 +77,9 @@ upstream {{ $host }} { {{ range $index, $value := $containers }} {{ $addrLen := len $value.Addresses }} - {{/* If only 1 port exposed, use that */}} - {{ if eq $addrLen 1 }} - {{ with $address := index $value.Addresses 0 }} - # {{$value.Name}} - server {{ $address.IP }}:{{ $address.Port }}; - {{ end }} {{/* If a VIRTUAL_NETWORK is specified use use its IP */}} - {{ else if $value.Env.VIRTUAL_NETWORK }} + {{ if $value.Env.VIRTUAL_NETWORK }} {{ range $i, $network := $value.Networks }} {{ if eq $network.Name $value.Env.VIRTUAL_NETWORK }} # Container: {{$value.Name}}@{{$network.Name}} @@ -93,6 +87,13 @@ upstream {{ $host }} { {{ end }} {{ end }} + {{/* If only 1 port exposed, use that */}} + {{ else if eq $addrLen 1 }} + {{ with $address := index $value.Addresses 0 }} + # {{$value.Name}} + server {{ $address.IP }}:{{ $address.Port }}; + {{ end }} + {{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var */}} {{ else if $value.Env.VIRTUAL_PORT }} {{ range $i, $address := $value.Addresses }}