Make port deterministic

This commit is contained in:
tanyadegurechaff 2017-04-28 17:05:54 +09:00 committed by Fernandez Ludovic
parent f621d7a2c4
commit 79cbe56a41
2 changed files with 23 additions and 10 deletions

View file

@ -594,9 +594,23 @@ func (p *Provider) getPort(container dockerData) string {
if label, err := getLabel(container, "traefik.port"); err == nil {
return label
}
for key := range container.NetworkSettings.Ports {
return key.Port()
// See iteration order in https://blog.golang.org/go-maps-in-action
var ports []nat.Port
for p := range container.NetworkSettings.Ports {
ports = append(ports, p)
}
less := func(i, j nat.Port) bool {
return i.Int() < j.Int()
}
nat.Sort(ports, less)
if len(ports) > 0 {
min := ports[0]
return min.Port()
}
return ""
}

View file

@ -227,14 +227,13 @@ func TestDockerGetPort(t *testing.T) {
})),
expected: "80",
},
// FIXME handle this better..
//{
// container: containerJSON(ports(nat.PortMap{
// "80/tcp": {},
// "443/tcp": {},
// })),
// expected: "80",
//},
{
container: containerJSON(ports(nat.PortMap{
"80/tcp": {},
"443/tcp": {},
})),
expected: "80",
},
{
container: containerJSON(labels(map[string]string{
"traefik.port": "8080",