diff --git a/cli/command/formatter/container.go b/cli/command/formatter/container.go index f357d2aac8..820e9ad126 100644 --- a/cli/command/formatter/container.go +++ b/cli/command/formatter/container.go @@ -377,7 +377,7 @@ func formGroup(key string, start, last uint16) string { group = fmt.Sprintf("%s-%d", group, last) } if ip != "" { - group = fmt.Sprintf("%s:%s->%s", ip, group, group) + group = fmt.Sprintf("%s->%s", net.JoinHostPort(ip, group), group) } return group + "/" + groupType } diff --git a/cli/command/formatter/container_test.go b/cli/command/formatter/container_test.go index ae3f7317ef..3c8552f666 100644 --- a/cli/command/formatter/container_test.go +++ b/cli/command/formatter/container_test.go @@ -589,6 +589,17 @@ func TestDisplayablePorts(t *testing.T) { }, expected: "4.3.2.1:8899->9988/tcp", }, + { + ports: []container.Port{ + { + IP: "::1", + PrivatePort: 9988, + PublicPort: 8899, + Type: "tcp", + }, + }, + expected: "[::1]:8899->9988/tcp", + }, { ports: []container.Port{ { @@ -600,6 +611,17 @@ func TestDisplayablePorts(t *testing.T) { }, expected: "4.3.2.1:9988->9988/tcp", }, + { + ports: []container.Port{ + { + IP: "::1", + PrivatePort: 9988, + PublicPort: 9988, + Type: "tcp", + }, + }, + expected: "[::1]:9988->9988/tcp", + }, { ports: []container.Port{ { @@ -628,6 +650,22 @@ func TestDisplayablePorts(t *testing.T) { }, expected: "1.2.3.4:9998-9999->9998-9999/udp", }, + { + ports: []container.Port{ + { + IP: "::1", + PublicPort: 9998, + PrivatePort: 9998, + Type: "udp", + }, { + IP: "::1", + PublicPort: 9999, + PrivatePort: 9999, + Type: "udp", + }, + }, + expected: "[::1]:9998-9999->9998-9999/udp", + }, { ports: []container.Port{ { @@ -644,6 +682,22 @@ func TestDisplayablePorts(t *testing.T) { }, expected: "1.2.3.4:8887->9998/udp, 1.2.3.4:8888->9999/udp", }, + { + ports: []container.Port{ + { + IP: "::1", + PublicPort: 8887, + PrivatePort: 9998, + Type: "udp", + }, { + IP: "::1", + PublicPort: 8888, + PrivatePort: 9999, + Type: "udp", + }, + }, + expected: "[::1]:8887->9998/udp, [::1]:8888->9999/udp", + }, { ports: []container.Port{ { @@ -688,9 +742,14 @@ func TestDisplayablePorts(t *testing.T) { PrivatePort: 2233, PublicPort: 3322, Type: "tcp", + }, { + IP: "::1", + PrivatePort: 2233, + PublicPort: 3322, + Type: "tcp", }, }, - expected: "4.3.2.1:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp", + expected: "4.3.2.1:3322->2233/tcp, [::1]:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp", }, { ports: []container.Port{