Make port deterministic
This commit is contained in:
parent
f621d7a2c4
commit
79cbe56a41
2 changed files with 23 additions and 10 deletions
|
@ -594,9 +594,23 @@ func (p *Provider) getPort(container dockerData) string {
|
||||||
if label, err := getLabel(container, "traefik.port"); err == nil {
|
if label, err := getLabel(container, "traefik.port"); err == nil {
|
||||||
return label
|
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 ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,14 +227,13 @@ func TestDockerGetPort(t *testing.T) {
|
||||||
})),
|
})),
|
||||||
expected: "80",
|
expected: "80",
|
||||||
},
|
},
|
||||||
// FIXME handle this better..
|
{
|
||||||
//{
|
container: containerJSON(ports(nat.PortMap{
|
||||||
// container: containerJSON(ports(nat.PortMap{
|
"80/tcp": {},
|
||||||
// "80/tcp": {},
|
"443/tcp": {},
|
||||||
// "443/tcp": {},
|
})),
|
||||||
// })),
|
expected: "80",
|
||||||
// expected: "80",
|
},
|
||||||
//},
|
|
||||||
{
|
{
|
||||||
container: containerJSON(labels(map[string]string{
|
container: containerJSON(labels(map[string]string{
|
||||||
"traefik.port": "8080",
|
"traefik.port": "8080",
|
||||||
|
|
Loading…
Reference in a new issue