colima icon indicating copy to clipboard operation
colima copied to clipboard

VS Code does not see docker engine is running via remote (SSH)

Open mrmachine opened this issue 2 years ago • 6 comments

I am using VS Code on my M1 MBP, with Docker via colima on my Intel iMac. But attempting to open my project in a dev container shows:

[34976506 ms] Start: Run in Host: docker version --format {{.Server.APIVersion}}
[34976639 ms] 
[34976641 ms] Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

If I open the project in a dev container in VS Code directly on the Intel iMac, it works.

With Docker Desktop running on the iMac (or a remote Ubuntu 20.04 LTS EC2), I can do Remote-SSH: Connect to Host... then open the project directory then Remote-Containers: Rebuild and Reopen in Container and it works.

My ~/.docker/config.json on the iMac is:

{
        "auths": {
                "https://index.docker.io/v1/": {}
        },
        "credsStore": "osxkeychain",
        "currentContext": "colima"
}

mrmachine avatar Jan 24 '22 22:01 mrmachine

This is not colima's fault 😄

VSCode's Docker / Remote Containers extension does not respect the currentContext in your ~/.docker/config.json.

In order to make VSCode use the colima Docker context you need to update the settings of the Docker extension.

On macOS press CMD + Shift + P -> Open Settings (JSON).

{
  // Example 1 - set the local Docker socket to use
  "docker.host": "unix:///Users/USERNAME/.colima/docker.sock",
  // Example 2 - set the Docker context to use
  "docker.context": "colima",
}

The setting(s) can be applied per workspace/directory if you add it to <workspace>/.vscode/settings.json

See: VSCode Documentation - Conntect Using Docker Contexts

Please close the issue if my answer resolves your issue as it is not related to colima itself.

nifr avatar Jan 26 '22 03:01 nifr

I have tried setting VSCODE setting as you mention and it does not work. That seems a VSCode issue. I even tried changing the Docker context globally which works only if you launch VSCode from that shell where the context is set. Otherwise, it still does not work.

The only fix that works which is what rancher-desktop or docker-desktop are doing is this:

sudo ln -sf ~/.colima/docker.sock /var/run/docker.sock

Hope this helps.

olegTarassov avatar Feb 03 '22 13:02 olegTarassov

thanks @olegTarassov that also worked for me !!!

Now VSCode works fine with colima.

@abiosoft I am on an Intel mac..

If anyone is on an Arm Mac, can they report back about if @olegTarassov fix works for them too ...

gedw99 avatar Feb 21 '22 08:02 gedw99

@olegTarassov 's solution works.

MacBook Pro (13-inch, M1, 2020)

> uname -a
Darwin MBP 21.4.0 Darwin Kernel Version 21.4.0: Mon Feb 21 20:36:53 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T8101 arm64

linjunpop avatar Mar 29 '22 05:03 linjunpop

On macOS press CMD + Shift + P -> Open Settings (JSON).

{
  // Example 1 - set the local Docker socket to use
  "docker.host": "unix:///Users/USERNAME/.colima/docker.sock",
  // Example 2 - set the Docker context to use
  "docker.context": "colima",
}

See: VSCode Documentation - Conntect Using Docker Contexts

Updating @nifr's answer. The correct config according to the docs is below.

Get your context details with docker context ls, and update your user/workspace settings.

"docker.environment": {
  "DOCKER_HOST": "unix:///Users/USER_NAME/.colima/docker.sock",
  "DOCKER_CONTEXT": "colima"
}

dogukancagatay avatar Feb 27 '23 15:02 dogukancagatay