Skip to content

infer unix:// prefix for path-like DOCKER_HOST values #6007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ZayaanRahman
Copy link

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

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.

Signed-off-by: Zayaan Rahman <126630377+ZayaanRahman@users.noreply.github.com>
@ZayaanRahman
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant