Skip to content

Commit 5805df0

Browse files
authored
Merge pull request #5365 from vvoland/5363-27.x
[27.x backport] cli/formatter: bracket IPv6 addrs prepended to ports
2 parents fb20f00 + 6ceb0ab commit 5805df0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

cli/command/formatter/container.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package formatter
55

66
import (
77
"fmt"
8+
"net"
89
"sort"
910
"strconv"
1011
"strings"
@@ -331,7 +332,8 @@ func DisplayablePorts(ports []types.Port) string {
331332
portKey := port.Type
332333
if port.IP != "" {
333334
if port.PublicPort != current {
334-
hostMappings = append(hostMappings, fmt.Sprintf("%s:%d->%d/%s", port.IP, port.PublicPort, port.PrivatePort, port.Type))
335+
hAddrPort := net.JoinHostPort(port.IP, strconv.Itoa(int(port.PublicPort)))
336+
hostMappings = append(hostMappings, fmt.Sprintf("%s->%d/%s", hAddrPort, port.PrivatePort, port.Type))
335337
continue
336338
}
337339
portKey = port.IP + "/" + port.Type

cli/command/formatter/container_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,16 @@ func TestDisplayablePorts(t *testing.T) {
471471
},
472472
"0.0.0.0:0->9988/tcp",
473473
},
474+
{
475+
[]types.Port{
476+
{
477+
IP: "::",
478+
PrivatePort: 9988,
479+
Type: "tcp",
480+
},
481+
},
482+
"[::]:0->9988/tcp",
483+
},
474484
{
475485
[]types.Port{
476486
{

0 commit comments

Comments
 (0)