From 5258d9797ffe10e71b8efb2243352ddc9625f4ce Mon Sep 17 00:00:00 2001 From: Alexander Zigelski Date: Thu, 16 Nov 2017 20:31:24 +0100 Subject: [PATCH] use rancher metadata service to get ip on rancher --- nginx.tmpl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nginx.tmpl b/nginx.tmpl index 5147fee..2cb94bc 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -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;