I am using the following setup
Remote system
VS Code - Connecting via SSH to the remote machine using "Remote Extension"
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

VS Code tries to refer to the "default" Docker context, althouhgh the "rootless" Docker context is selected, which in my case is:
$ echo $DOCKER_HOST
unix:///run/user/1001/docker.sock
Also when the "docker.host" is set to the one of the rootless Docker or if the "docker.context" is set to the "rootless", using "Attach Visual Studio Code" will fail with the same error message.
Update 2023-03-06:
When running docker context use rootless I get the following output:

And the VSCode Docker extension shows the following:

But when I run then run docker context ls in the command line I get the following output:

But the value of DOCKER_HOST is set to the rootless context.
$ echo DOCKER_HOST
unix:///run/user/1001/docker.sock
When running docker ps it lists the container running in the rootless context.
Is this the reason it does not work as expected?
Workaround - What did work out is the following:
docker context create <some_name> --docker host="ssh://<user>@<ip address>Does someone know how to fix the issue, so that it is possible to use "Attach Visual Studio Code" directly from the VS Code window being connected via ssh to the remote system?
I had a similar issue running rootless docker. It seemed it was not honoring environment variables in ~/.bashrc (like DOCKER_HOST)
In the logs I found that it was loading /bin/sh, rather than /bin/bash. In this case I am using a managed login user that does not appear in local /etc/passwd. Moving applicable environment variables into ~/.profile fixed my issues.
# container logs from vscode
[13689 ms] userEnvProbe: loginInteractiveShell (default)
[13689 ms] userEnvProbe: not found in cache
[13690 ms] userEnvProbe shell: /bin/sh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With