infer unix:// prefix for path-like DOCKER_HOST values
This change improves the handling of DOCKER_HOST by automatically inferring a "unix://" prefix when the host string starts with "/", "./", or "../", indicating a unix socket path. Previously, these values were incorrectly interpreted as TCP addresses, leading to confusing error messages.
- What I did
Improved the parsing logic of DOCKER_HOST to detect when a value looks like a path and automatically treat it as a Unix socket.
- How I did it
Modified parseDockerDaemonHost() to use the "unix://" protocol for addr strings starting with "/", "./", or ".", where no protocol is specified. Addresses without protocol prefixes that do not resemble a path are given the "tcp://" protocol.
- How to verify it
Compare the output of running docker version with DOCKER_HOST set to "/invalid.sock":
$ DOCKER_HOST=/invalid.sock docker version
Client:
Version: 27.5.1
API version: 1.47
Go version: go1.22.11
Git commit: 9f9e405
Built: Wed Jan 22 13:39:08 2025
OS/Arch: linux/arm64
Context: default
Cannot connect to the Docker daemon at tcp://localhost:2375/invalid.sock. Is the docker daemon running?
After this change, the error message shows that the host is interpreted as a unix socket.
$ DOCKER_HOST=/invalid.sock docker version
Client:
Version: 27.5.1
API version: 1.47
Go version: go1.22.11
Git commit: 9f9e405
Built: Wed Jan 22 13:39:08 2025
OS/Arch: linux/arm64
Context: default
Cannot connect to the Docker daemon at unix:///invalid.sock. Is the docker daemon running?
- Human readable description for the release notes
Improved error clarity for DOCKER_HOST values that are Unix socket paths by inferring the "unix://" prefix when omitted.
- A picture of a cute animal (not mandatory but encouraged)
Fixes #5846
I went with the approach @thaJeztah suggested in the issue, inferring unix:// when the DOCKER_HOST value looks like a path (starts with /, ./, or ../). Let me know if you’d prefer to take the stricter approach (requiring explicit protocols and improving the error message instead). Happy to revise either way!