Skip to content

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

Open
@AkihiroSuda

Description

@AkihiroSuda
Collaborator

Description

$ 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?

This error message is quite confusing, as the original invalid DOCKER_HOST value does not contain tcp://localhost:2375.
Probably it should return an error like invalid $DOCKER_HOST value "/invalid.sock": must start with "unix://" or "tcp://"

Activity

thaJeztah

thaJeztah commented on Feb 20, 2025

@thaJeztah
Member

Thx! Yeah, I think there's some dubious (and inconsistent) handling for these in some areas.

I suspect I may have introduced this when I replaced some code with url.Parse (adding a scheme if missing), but it's possible it was elsewhere as I found multiple places where logic for this was implemented, but ever-so-slightly different.

thaJeztah

thaJeztah commented on Feb 20, 2025

@thaJeztah
Member

Oh, and if we're gonna add that to the error message, ssh:// should probably also be there.

I suspect part of this may be due to logic where hostname (without scheme) would be considered tcp://hostname, and we may be using tcp as default if not set, which in this case, gets seen as <host missing>/invalid.sock -> <default host and scheme>/invalid.sock.

But perhaps in this case, we should consider checking if the value starts with something that indicates a path (/, ./), as in that case the user very likely meant "path to a socket".

ZayaanRahman

ZayaanRahman commented on Apr 6, 2025

@ZayaanRahman

Hi! I'm interested in contributing to the Docker cli, and was wondering if this was a good issue I could get started on.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @neersighted@thaJeztah@AkihiroSuda@ZayaanRahman

      Issue actions

        `DOCKER_HOST` without `unix://` prefix prints a confusing error: `Cannot connect to the Docker daemon at tcp://localhost:2375/foo.sock.` · Issue #5846 · docker/cli