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
7 changes: 6 additions & 1 deletion opts/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ func parseDockerDaemonHost(addr string) (string, error) {
proto, host, hasProto := strings.Cut(addr, "://")
if !hasProto && proto != "" {
host = proto
proto = "tcp"
// if the addr string starts with "/", "./", or "../", the user very likely meant "path to a socket"
if strings.HasPrefix(host, "/") || strings.HasPrefix(host, "./") || strings.HasPrefix(host, "../") {
proto = "unix"
} else {
proto = "tcp"
}
}

switch proto {
Expand Down
3 changes: 3 additions & 0 deletions opts/hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func TestParseHost(t *testing.T) {
"unix://path/to/socket": "unix://path/to/socket",
"npipe://": "npipe://" + defaultNamedPipe,
"npipe:////./pipe/foo": "npipe:////./pipe/foo",
"/some.sock": "unix:///some.sock",
"./single/dot": "unix://./single/dot",
"../double/dot": "unix://../double/dot",
}

for _, value := range invalid {
Expand Down