diff --git a/provider/docker/config.go b/provider/docker/config.go index 7ee1e2c76..c96f1940b 100644 --- a/provider/docker/config.go +++ b/provider/docker/config.go @@ -3,6 +3,7 @@ package docker import ( "context" "fmt" + "net" "strconv" "strings" "text/template" @@ -336,7 +337,7 @@ func (p *Provider) getServers(containers []dockerData) map[string]types.Server { } servers[provider.Normalize(serverName)] = types.Server{ - URL: fmt.Sprintf("%s://%s:%s", protocol, ip, port), + URL: fmt.Sprintf("%s://%s", protocol, net.JoinHostPort(ip, port)), Weight: label.GetIntValue(container.SegmentLabels, label.TraefikWeight, label.DefaultWeight), } } diff --git a/provider/ecs/config.go b/provider/ecs/config.go index 0fc8b8792..eae4736f4 100644 --- a/provider/ecs/config.go +++ b/provider/ecs/config.go @@ -2,6 +2,7 @@ package ecs import ( "fmt" + "net" "strconv" "strings" "text/template" @@ -134,7 +135,7 @@ func getServers(instances []ecsInstance) map[string]types.Server { serverName := provider.Normalize(fmt.Sprintf("server-%s-%s", instance.Name, instance.ID)) servers[serverName] = types.Server{ - URL: fmt.Sprintf("%s://%s:%s", protocol, host, port), + URL: fmt.Sprintf("%s://%s", protocol, net.JoinHostPort(host, port)), Weight: label.GetIntValue(instance.TraefikLabels, label.TraefikWeight, label.DefaultWeight), } } diff --git a/provider/marathon/config.go b/provider/marathon/config.go index 4b90de740..aaa0725fc 100644 --- a/provider/marathon/config.go +++ b/provider/marathon/config.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "math" + "net" "strconv" "strings" "text/template" @@ -340,7 +341,7 @@ func (p *Provider) getServer(app appData, task marathon.Task) (string, *types.Se serverName := provider.Normalize("server-" + app.ID + "-" + task.ID + getSegmentNameSuffix(app.SegmentName)) return serverName, &types.Server{ - URL: fmt.Sprintf("%s://%s:%v", protocol, host, port), + URL: fmt.Sprintf("%s://%s", protocol, net.JoinHostPort(host, port)), Weight: label.GetIntValue(app.SegmentLabels, label.TraefikWeight, label.DefaultWeight), }, nil } diff --git a/provider/mesos/config.go b/provider/mesos/config.go index a5d874c5f..c9b32e587 100644 --- a/provider/mesos/config.go +++ b/provider/mesos/config.go @@ -3,6 +3,7 @@ package mesos import ( "fmt" "math" + "net" "strconv" "strings" "text/template" @@ -185,7 +186,7 @@ func (p *Provider) getServers(tasks []taskData) map[string]types.Server { serverName := "server-" + getID(task) servers[serverName] = types.Server{ - URL: fmt.Sprintf("%s://%s:%s", protocol, host, port), + URL: fmt.Sprintf("%s://%s", protocol, net.JoinHostPort(host, port)), Weight: getIntValue(task.TraefikLabels, label.TraefikWeight, label.DefaultWeight, math.MaxInt32), } } diff --git a/provider/rancher/config.go b/provider/rancher/config.go index 255850fe6..e52405edb 100644 --- a/provider/rancher/config.go +++ b/provider/rancher/config.go @@ -2,6 +2,7 @@ package rancher import ( "fmt" + "net" "strconv" "strings" "text/template" @@ -181,7 +182,7 @@ func getServers(service rancherData) map[string]types.Server { serverName := "server-" + strconv.Itoa(index) servers[serverName] = types.Server{ - URL: fmt.Sprintf("%s://%s:%s", protocol, ip, port), + URL: fmt.Sprintf("%s://%s", protocol, net.JoinHostPort(ip, port)), Weight: weight, } }