mirror of https://github.com/docker/cli.git
cli/formatter: bracket IPv6 addrs prepended to ports
On `docker ps`, port bindings with an IPv6 HostIP should have their addresses put into brackets when joining them to their ports. RFC 3986 (Section 3.2.2) stipulates that IPv6 addresses should be enclosed within square brackets. This RFC is only about URIs. However, doing so here helps user identifier what's part of the IP address and what's the port. It also makes it easier to copy/paste that '[addr]:port' into other software (including browsers). Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
parent
35666cf7cb
commit
964155cd27
|
@ -5,6 +5,7 @@ package formatter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -331,7 +332,8 @@ func DisplayablePorts(ports []container.Port) string {
|
||||||
portKey := port.Type
|
portKey := port.Type
|
||||||
if port.IP != "" {
|
if port.IP != "" {
|
||||||
if port.PublicPort != current {
|
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
|
continue
|
||||||
}
|
}
|
||||||
portKey = port.IP + "/" + port.Type
|
portKey = port.IP + "/" + port.Type
|
||||||
|
|
|
@ -558,6 +558,16 @@ func TestDisplayablePorts(t *testing.T) {
|
||||||
},
|
},
|
||||||
expected: "0.0.0.0:0->9988/tcp",
|
expected: "0.0.0.0:0->9988/tcp",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ports: []container.Port{
|
||||||
|
{
|
||||||
|
IP: "::",
|
||||||
|
PrivatePort: 9988,
|
||||||
|
Type: "tcp",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: "[::]:0->9988/tcp",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ports: []container.Port{
|
ports: []container.Port{
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue