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

cannot connect to docker #4471

Open
sivom opened this issue Jan 15, 2025 · 9 comments
Open

cannot connect to docker #4471

sivom opened this issue Jan 15, 2025 · 9 comments

Comments

@sivom
Copy link

sivom commented Jan 15, 2025

Does this occur consistently?
Repro steps:

Version: 1.29.3
OS: linux
OS Release: 6.1.0-28-amd64
Product: code-server
Product Version: 1.96.2
Language: en

Image

@sivom
Copy link
Author

sivom commented Jan 15, 2025

I am using the extenstion in code server (vscode online server)
I have debian running the docker containers, code server is a container, i exported docker.sock as volume
tried DOCKER_HOST unix:///var/run/docker.sock nothing helped

$ docker context ls
NAME DESCRIPTION DOCKER ENDPOINT ERROR
default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock
docker-codeserver tcp://docker:2375
$ docker -v
Docker version 27.4.1, build b9d17ea

Image

@bwateratmsft
Copy link
Collaborator

What do you see if you do docker container ls in the terminal?

@Baalakay
Copy link

Baalakay commented Jan 19, 2025

Having same issue on MacBook Pro M3.

On Linux, you should enable rootless Docker and set the generated Docker context to "rootless" (more secure) or enable Docker CLI for the non-root user account (less secure) that will be used to run VS Code.

docker context ls                                                                                                                    
NAME              DESCRIPTION                               DOCKER ENDPOINT                               ERROR                                                                 
default           Current DOCKER_HOST based configuration   unix:///var/run/docker.sock                                                                                         [13:40:33]
desktop-linux *   Docker Desktop                            unix:///Users/REMOVED/.docker/run/docker.sock      
(main✗) $ docker container ls                                                                                                                  
CONTAINER ID   IMAGE                                                                                            COMMAND                  CREATED       STATUS         PORTS     NAMES
0dc21c64d89e   vsc-44c23d85ac5d09e2bf5163331b46b77ca0fc02ced44c88d3b546f1592ea64c6f   "/bin/sh -c 'echo Co…"   10 days ago   Up 7 minutes             mystifying_diracf        Inspect changes to files or directories on a container's filesystem

@bwateratmsft
Copy link
Collaborator

@Baalakay are you using Docker Desktop for Mac or some other installation of Docker?

@Baalakay
Copy link

Docker Desktop for Mac. I also installed the vscode docker extension on the devcontainer just to see what happens, and I no longer get the "Failed to Connect" errors as the OP, but now get this but still don't see any running containers. I'm thinking it's probably looking just for containers on the devcontainer and not local ("Docker-in-Docker)?

Image

@bwateratmsft
Copy link
Collaborator

bwateratmsft commented Jan 21, 2025

Right, by default it would only show the containers inside the container (Docker-in-Docker), not beside the container (Docker-from-Docker)--you have to volume map unix:///var/run/docker.sock and possibly do some other stuff too.

We simply use the CLI to find containers (as opposed to the HTTP endpoint), so as long as the CLI is working and the relevant environment variables are the same, you can expect the Docker extension to work. So if you're seeing the same error as OP, I suspect that for some reason when we run docker -v it is not working. The most likely culprit is that docker isn't on the PATH environment variable in the environment VSCode runs in.

If you do the command "Developer: Set Log Level...", select the Docker log, and set the log level to Trace, it will spit a bunch of info including the full environment to the Docker output log. That might offer some clues.

@Baalakay
Copy link

Ok, will try the volume map and report back. Thx!

@Baalakay
Copy link

So I as able to get it working simply by adding this feature to the devcontainer.json: https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker

Also, installed this to get the stats shown at the bottom, like I was originally looking for.
https://marketplace.visualstudio.com/items?itemName=igorjrd.docker-stats

All good now, thanks for the help @bwateratmsft

Image

@bwateratmsft
Copy link
Collaborator

Glad it's working! I'll keep this open in case @sivom comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants