Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions opts/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,13 @@ func ParseTCPAddr(tryAddr string, defaultAddr string) (string, error) {
}
host, port, err := net.SplitHostPort(u.Host)
if err != nil {
// try port addition once
host, port, err = net.SplitHostPort(net.JoinHostPort(u.Host, defaultPort))
// try port addition once; JoinHostPort adds its own brackets around
// IPv6 literals, so strip the ones url.Parse left on u.Host.
bare := u.Host
if len(bare) > 1 && bare[0] == '[' && bare[len(bare)-1] == ']' {
bare = bare[1 : len(bare)-1]
}
host, port, err = net.SplitHostPort(net.JoinHostPort(bare, defaultPort))
}
if err != nil {
return "", fmt.Errorf("invalid bind address format: %s", tryAddr)
Expand Down
4 changes: 4 additions & 0 deletions opts/hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func TestParseDockerDaemonHost(t *testing.T) {
"0.0.0.1:": "tcp://0.0.0.1:2375",
"0.0.0.1:5555": "tcp://0.0.0.1:5555",
"0.0.0.1:5555/path": "tcp://0.0.0.1:5555/path",
"[::1]": "tcp://[::1]:2375",
"[0:0:0:0:0:0:0:1]": "tcp://[0:0:0:0:0:0:0:1]:2375",
"[::1]:": "tcp://[::1]:2375",
"[::1]:5555/path": "tcp://[::1]:5555/path",
"[0:0:0:0:0:0:0:1]:": "tcp://[0:0:0:0:0:0:0:1]:2375",
Expand Down Expand Up @@ -113,6 +115,8 @@ func TestParseTCP(t *testing.T) {
":6666/path": "tcp://127.0.0.1:6666/path",
"tcp://:7777": "tcp://127.0.0.1:7777",
"tcp://:7777/path": "tcp://127.0.0.1:7777/path",
"[::1]": "tcp://[::1]:2376",
"[::1]/path": "tcp://[::1]:2376/path",
"[::1]:": "tcp://[::1]:2376",
"[::1]:5555": "tcp://[::1]:5555",
"[::1]:5555/path": "tcp://[::1]:5555/path",
Expand Down