Skip to content

connhelper: include ssh remote host in dummy client URL (fixes #5604) - #7229

Open
adisivaprasad wants to merge 1 commit into
docker:masterfrom
adisivaprasad:fix-5604-ssh-host-in-errors
Open

connhelper: include ssh remote host in dummy client URL (fixes #5604)#7229
adisivaprasad wants to merge 1 commit into
docker:masterfrom
adisivaprasad:fix-5604-ssh-host-in-errors

Conversation

@adisivaprasad

Copy link
Copy Markdown

Description

When connecting to a daemon over ssh://, ConnectionHelper.Host is used as a dummy URL for the API client (Go's stdlib requires a valid hostname in requests). That dummy value — http://docker.example.com — also ends up in connection error messages, so a failed connection reports:

Error: Cannot connect to the Docker daemon at http://docker.example.com. Is the docker daemon running?

which makes users believe the client is trying to connect to docker.example.com instead of the remote host they configured. This was reported in #5604; as suggested there, this change makes the error mention the hostname the user actually provided.

What this changes

For ssh connections, the dummy URL now embeds the remote hostname (and the port, when non-default), so the error reads e.g.:

Error: Cannot connect to the Docker daemon at http://myserver.local. Is the docker daemon running?

The URL remains a pure dummy: the actual connection is established through the ssh Dialer (docker system dial-stdio over ssh), so request transport behavior is unchanged. Command-based connection helpers (GetCommandConnectionHelper) keep the generic dummy host since there is no meaningful hostname to surface.

Tests

Added TestConnectionHelperHostIncludesRemoteHost covering plain/user+host/custom-port/explicit-default-port ssh URLs, and TestGetCommandConnectionHelperHost pinning the generic dummy for command-based helpers. go test ./cli/connhelper/... passes.

AI assistance disclosure

This change was implemented with assistance from an AI coding agent (design direction informed by the discussion in #5604); the resulting code has been reviewed for correctness and follows the existing style of the package.

Changelog

fix: make connection error messages for ssh-based connections point to the remote host the user configured instead of "docker.example.com"

A picture of a cute animal (not mandatory but encouraged)

When connecting to a daemon over ssh, ConnectionHelper.Host is used as a
dummy URL for the API client, since Go's stdlib requires a valid hostname
in requests. This dummy URL (http://docker.example.com) also showed up in
connection error messages, which made users believe the CLI was trying to
connect to docker.example.com instead of the remote host they configured:

    Error: Cannot connect to the Docker daemon at http://docker.example.com.

Use the ssh target's hostname (and non-default port) in the dummy URL so
that connection errors point at the host the user configured, e.g.:

    Error: Cannot connect to the Docker daemon at http://myserver.local.

The URL remains a dummy; the actual connection is established via the ssh
dialer, so this does not change how requests are transported.

Fixes: docker#5604
Signed-off-by: adisivaprasad <adisivaprasad@users.noreply.github.com>
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.

On remote connect failure, docker erronously refers to "docker.example.com"

1 participant