diff --git a/cli/command/formatter/container.go b/cli/command/formatter/container.go index 2407e9c81fb3..203e437c6997 100644 --- a/cli/command/formatter/container.go +++ b/cli/command/formatter/container.go @@ -5,6 +5,7 @@ package formatter import ( "fmt" + "net" "sort" "strconv" "strings" @@ -331,7 +332,8 @@ func DisplayablePorts(ports []container.Port) string { portKey := port.Type if port.IP != "" { if port.PublicPort != current { - hostMappings = append(hostMappings, fmt.Sprintf("%s:%d->%d/%s", port.IP, port.PublicPort, port.PrivatePort, port.Type)) + hAddrPort := net.JoinHostPort(port.IP, strconv.Itoa(int(port.PublicPort))) + hostMappings = append(hostMappings, fmt.Sprintf("%s->%d/%s", hAddrPort, port.PrivatePort, port.Type)) continue } portKey = port.IP + "/" + port.Type diff --git a/cli/command/formatter/container_test.go b/cli/command/formatter/container_test.go index 379927a36a31..ae3f7317ef7c 100644 --- a/cli/command/formatter/container_test.go +++ b/cli/command/formatter/container_test.go @@ -558,6 +558,16 @@ func TestDisplayablePorts(t *testing.T) { }, expected: "0.0.0.0:0->9988/tcp", }, + { + ports: []container.Port{ + { + IP: "::", + PrivatePort: 9988, + Type: "tcp", + }, + }, + expected: "[::]:0->9988/tcp", + }, { ports: []container.Port{ {