Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mrmachine opened this issue Jan 24, 2022 · 6 comments
Open

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

mrmachine opened this issue Jan 24, 2022 · 6 comments

Comments

@mrmachine
Copy link

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"
}
@nifr
Copy link

nifr commented Jan 26, 2022

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.

@olegTarassov
Copy link

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.

@gedw99
Copy link

gedw99 commented Feb 21, 2022

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 ...

@linjunpop
Copy link

linjunpop commented Mar 29, 2022

@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

@dogukancagatay
Copy link

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"
}

@meehanman
Copy link

Just to add to the above comment that worked for me.

Run the following commands to check your Colima Socket Location, and that your Docker Context is Colima and the Endpoint is correct:

❯ colima status -e
INFO[0000] colima is running using QEMU                 
INFO[0000] arch: x86_64                                 
INFO[0000] runtime: docker                              
INFO[0000] mountType: sshfs                             
INFO[0000] socket: unix:///Users/MyUser/.colima/default/docker.sock 
INFO[0000] cpu: 2                                       
INFO[0000] mem: 2GiB                                    
INFO[0000] disk: 60GiB
❯ docker context ls
NAME              DESCRIPTION                               DOCKER ENDPOINT                                   ERROR
colima            colima                                    unix:///Users/MyUser/.colima/default/docker.sock
default *         Current DOCKER_HOST based configuration   unix:///Users/MyUser/.colima/default/docker.sock      
Warning: DOCKER_HOST environment variable overrides the active context. To use a context, either set the global --context flag, or unset DOCKER_HOST environment variable.

Then in VSCode, you can either:

  1. Edit the Docker Settings via the GUI
    a. Cmd + P then type> Preferences: Open User Settings (UI) + Enter, then into the Settings Search enter @ext:ms-azuretools.vscode-docker, scroll down to Docker: Environment and add two new Items DOCKER_HOST:unix:///Users/MyUser/.colima/default/docker.sock and DOCKER_CONTEXT:colima
  2. Edit the global Preferences
    a.Cmd + P then type> Preferences: Open User Settings (JSON) and Enter and add the following docker.environment object into your settings:
...
  "some-other-settings: "",
...
  "docker.environment": {
    "DOCKER_HOST": "unix:///Users/MyUser/.colima/default/docker.sock",
    "DOCKER_CONTEXT": "colima"
  },
...
  "[python]": {
...

NOTE: After changing these settings, you will have to restart VSCode to see this changes propagated.

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

No branches or pull requests

7 participants