use rancher metadata service to get ip on rancher

This commit is contained in:
Alexander Zigelski 2017-11-16 20:31:24 +01:00
parent a6e8fae7f5
commit 5258d9797f
No known key found for this signature in database
GPG key ID: ECBD4528C336757D

View file

@ -1,6 +1,7 @@
{{ $CurrentContainer := where $ "ID" .Docker.CurrentContainerID | first }}
{{ define "upstream" }}
{{ $rancherIP := or (index .Container.Labels "io.rancher.container.ip") "" }}
{{ if .Address }}
{{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}}
{{ if and .Container.Node.ID .Address.HostPort }}
@ -11,6 +12,10 @@
# {{ .Container.Name }}
server {{ .Network.IP }}:{{ .Address.Port }};
{{ end }}
{{ else if $rancherIP }}
# rancher: {{ index .Container.Labels "io.rancher.container.name" }} {{ printf "%s" $rancherIP }}
{{ $port := coalesce .Container.Env.VIRTUAL_PORT "80" }}
server {{ printf "%s" (index (splitN $rancherIP "/" 2) 0) }}:{{ printf "%s" $port }};
{{ else if .Network }}
# {{ .Container.Name }}
server {{ .Network.IP }} down;