Skip to content

fix(opts): reject scheme-less socket paths in DOCKER_HOST instead of treating them as TCP hosts - #7550

Open
Anuj-er wants to merge 1 commit into
docker:masterfrom
Anuj-er:fix/docker-host-validation-5846
Open

Anuj-er wants to merge 1 commit into
docker:masterfrom
Anuj-er:fix/docker-host-validation-5846

Conversation

@Anuj-er

@Anuj-er Anuj-er commented Nov 25, 2026

Copy link
Copy Markdown

Fixes #5846

Root cause

A scheme-less DOCKER_HOST value is unconditionally treated as a TCP host in parseDockerDaemonHost. So DOCKER_HOST=/invalid.sock docker version reports Cannot connect to the Docker daemon at tcp://localhost:2375/invalid.sock — a URL the user never typed, built by ParseTCPAddr from an empty host (defaulted to localhost:2375) plus the path.

Fix

Reject scheme-less values that look like filesystem paths before defaulting to TCP, with an error naming the bad input and the fix: invalid host address "/invalid.sock": a socket path must use the "unix://" scheme, e.g. "unix:///invalid.sock". Only values starting with / are rejected, so all currently-valid bare forms keep working (localhost:5555, 0.0.0.1:5555, :6666, [::1]:5555, localhost:5555/path). The error deliberately does not name DOCKER_HOST, because ParseHost is shared with the -H flag. One fix in parseDockerDaemonHost covers both surfaces.

Tests

  • TestParseDockerDaemonHost: /invalid.sock and /run/docker.sock now expect the new error.
  • TestParseHost: /invalid.sock added to the invalid cases.
  • Full opts package passes; gofmt clean. Verified the new tests fail without the fix and pass with it.

Copilot AI balanced review requested due to automatic review settings November 25, 2026 23:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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