I am having a similar problem, but with setting a context. I have a Virtualbox VM (Ubuntu 20) running on my Mac. In the VM I have Docker installed rootlessly. The VM is called vmname and the user is username. Virtualbox exposes the VM port 22 on Mac port 3022. Docker client and server are both version 20.10.10.
I have this in my ~/.ssh/config file:
Host vmname
HostName localhost
User username
Port 3022
So ssh works correctly:
mac$ ssh vmname
works correctly and gives me the vm console prompt.
vmname$ docker info
works correctly, giving me client and server info. Going back to the Mac,
mac$ unset DOCKER_HOST
mac$ docker context create vmname --docker "host=ssh://vmname"
mac$ docker context use vmname
seems to work correctly, because:
mac$ docker context ls
NAME TYPE DOCKER ENDPOINT
vmname * moby ssh://vmname
But here’s the problem:
mac$ docker info
Client:
Context: vmname
Debug Mode: false
Plugins:
buildx: Build with BuildKit (Docker Inc., v0.6.3)
compose: Docker Compose (Docker Inc., v2.1.1)
scan: Docker Scan (Docker Inc., 0.9.0)
Server:
ERROR: Cannot connect to the Docker daemon at http://docker.example.com. Is the docker daemon running?
errors pretty printing info
There seems to be a clue on Github in docker/engine/client/errors.go; it looks as though some doRequest() invocation is confused about the host:
// Error returns a string representation of an errConnectionFailed
func (err errConnectionFailed) Error() string {
if err.host == "" {
return "Cannot connect to the Docker daemon. Is the docker daemon running on this host?"
}
return fmt.Sprintf("Cannot connect to the Docker daemon at %s. Is the docker daemon running?", err.host)
}
If I power down the VM, I get a different error, which seems to imply that when the VM is running the ssh connection is getting through, but the Docker server is getting confused?
mac$ docker info
Client:
<same>
Server:
ERROR: error during connect: Get "http://docker.example.com/v1.24/info": command [ssh -- vmname docker system dial-stdio] has exited with exit status 255, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=ssh: connect to host localhost port 3022: Connection refused
I can’t find any other reports of this problem on Google, so I assume I am doing something very stupid. Any idea what?