Skip to content

fix: default to unix scheme when DOCKER_HOST is a filesystem path#7060

Open
amarkdotdev wants to merge 2 commits into
docker:masterfrom
amarkdotdev:fix/docker-host-missing-scheme
Open

fix: default to unix scheme when DOCKER_HOST is a filesystem path#7060
amarkdotdev wants to merge 2 commits into
docker:masterfrom
amarkdotdev:fix/docker-host-missing-scheme

Conversation

@amarkdotdev

Copy link
Copy Markdown

Description

When DOCKER_HOST is set to a filesystem path without a unix:// prefix (e.g. DOCKER_HOST=/var/run/docker.sock), the CLI produces a confusing error:

Cannot connect to the Docker daemon at tcp://localhost:2375/var/run/docker.sock. Is the docker daemon running?

The path gets misinterpreted as a TCP address because parseDockerDaemonHost defaults to the tcp protocol when no scheme is present.

Root cause

In opts/hosts.go, parseDockerDaemonHost splits on :// and defaults any scheme-less address to tcp:

if !hasProto && proto != "" {
    host = proto
    proto = "tcp"  // always defaults to tcp
}

Fix

When the scheme-less address starts with / or ./ (i.e. it's clearly a filesystem path), default to unix instead of tcp. This matches the user's intent and either connects successfully or produces a clear, relevant error.

Before:

$ DOCKER_HOST=/var/run/docker.sock docker version
Cannot connect to the Docker daemon at tcp://localhost:2375/var/run/docker.sock.

After:

$ DOCKER_HOST=/var/run/docker.sock docker version
# connects normally (equivalent to unix:///var/run/docker.sock)

Testing

  • Added test cases to TestParseDockerDaemonHost for /var/run/docker.sock and ./run/docker.sock
  • Verified the parsing logic with a standalone reproduction covering path, hostname, and explicit-scheme inputs
  • Existing tcp and explicit unix:// cases remain unchanged

Fixes #5846

…ze() method in the image formatter used HumanSizeWithPrecision with precision=3, which causes fmt %g to emit scientific notation (1e+03MB) when a size rounds to exactly 1000 in its current unit (e.g. an image of ~999.5 MB). Switch to HumanSize() which uses precision=4 (the standard across the rest of the CLI) and avoids this edge case while still producing compact human-readable output. Fixes docker#3091 Signed-off-by: Aaron <aaroniofjm@gmail.com>
When DOCKER_HOST is set to a filesystem path without a scheme
(e.g. /var/run/docker.sock), parseDockerDaemonHost previously
defaulted to the "tcp" protocol, producing a confusing error:
"Cannot connect to the Docker daemon at tcp://localhost:2375/foo.sock"

Now, if the address starts with "/" or "./", the parser defaults
to "unix" instead of "tcp", which matches the user's intent and
produces a correct connection or a clear error.

Fixes docker#5846

Signed-off-by: Aaron <aaroniofjm@gmail.com>
@amarkdotdev amarkdotdev force-pushed the fix/docker-host-missing-scheme branch from 93a9129 to 0d1bf0c Compare June 18, 2026 15:04
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.

1 participant