Docker corrections with long hostnames

This commit is contained in:
emile 2015-09-10 15:12:28 +02:00
parent 0dde11aa86
commit e60e955f90
2 changed files with 6 additions and 3 deletions

View file

@ -24,7 +24,7 @@ var DockerFuncMap = template.FuncMap{
return value return value
} }
} }
return container.Config.Hostname return getHost(container)
}, },
"getPort": func(container docker.Container) string { "getPort": func(container docker.Container) string {
for key, value := range container.Config.Labels { for key, value := range container.Config.Labels {
@ -37,6 +37,9 @@ var DockerFuncMap = template.FuncMap{
} }
return "" return ""
}, },
"replace": func(s1 string, s2 string, s3 string) string {
return strings.Replace(s3, s1, s2, -1)
},
"getHost": getHost, "getHost": getHost,
} }
@ -113,5 +116,5 @@ func getHost(container docker.Container) string {
return value return value
} }
} }
return strings.TrimPrefix(container.Name, "/") return strings.Replace(strings.Replace(container.Name, "/", "", -1), ".", "-", -1)
} }

View file

@ -1,5 +1,5 @@
[backends]{{range .Containers}} [backends]{{range .Containers}}
[backends.backend-{{getBackend .}}.servers.server-{{.Name | replace "/"}}] [backends.backend-{{getBackend .}}.servers.server-{{.Name | replace "/" "" | replace "." "-"}}]
url = "http://{{.NetworkSettings.IPAddress}}:{{getPort .}}" url = "http://{{.NetworkSettings.IPAddress}}:{{getPort .}}"
{{end}} {{end}}