Skip to content

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

Open
ZayaanRahman wants to merge 1 commit into
docker:masterfrom
ZayaanRahman:5846-fix-docker-host-error-prefix
Open

infer unix:// prefix for path-like DOCKER_HOST values#6007
ZayaanRahman wants to merge 1 commit into
docker:masterfrom
ZayaanRahman:5846-fix-docker-host-error-prefix

Conversation

@ZayaanRahman

Copy link
Copy Markdown

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
Copy Markdown
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!

@AkihiroSuda

Copy link
Copy Markdown
Collaborator

Maybe need rebase to trigger the CI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOCKER_HOST without unix:// prefix prints a confusing error: Cannot connect to the Docker daemon at tcp://localhost:2375/foo.sock.

2 participants