docker / dev-environments

60 stars 32 forks source link

Got permission denied while trying to connect to the Docker daemon socket after restarting Docker for Desktop #110

Open kantesilvestrs opened 2 years ago

kantesilvestrs commented 2 years ago

Describe the bug Dev environment throws Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version": dial unix /var/run/docker.sock: connect: permission denied message when trying to interact with docker, e.g. docker stats after Docker for Desktop has been restarted.

To Reproduce Steps to reproduce the behavior:

  1. Create new dev environment
  2. Open environment in VS Code
  3. Run command docker stats from VS Code terminal to see current running containers
  4. Close VS Code
  5. Restart Docker for Desktop
  6. Open dev environment in VS Code
  7. Run command docker stats from VS Code terminal
  8. Now an error message is displayed Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version": dial unix /var/run/docker.sock: connect: permission denied

Expected behavior Running docker commands after Docker for Desktop restart should yield same results when the dev environment is just created and launched.

Screenshots image

Desktop (please complete the following information):

Version of Docker Desktop:
You can find the version by clicking on the About Docker Desktop menu

Version

4.7.0 (77141)

Engine: 20.10.14

Compose: 1.29.2

Credential Helper: v0.6.4

Kubernetes: v1.22.5

Snyk: v1.827.0

Additional context I noticed this issue while trying to run a docker instance from the dev environment

htcarr3 commented 1 year ago

Is there any update on this? I have the same issue. On restart my dev environment user requires sudo with docker commands

KieranJeffreySmart commented 1 year ago

I also have this issue. When trying to perform docker commands I get permission denied. I have tried adding the user to the docker group, which seems to exist, but this asks for a password, which I dont have

jw-websensa commented 1 year ago

I am also facing the same issue. After some troubleshooting I noticed two very suspicious things:

  1. When I am checking if vscode user is part of docker group though group command, it looks like it is not. However, I also looked inside /etc/group file and vscode user is included there:

    ...
    docker:x:1001:vscode
    ...
  2. The owner user and group of docker socket are both set to root. I changed group to docker, however (because of 1. most probably) it did not solve the issue.

jfrumar-infinitusai commented 1 year ago

It looks like the gid of docker.sock is now set to 800 whenever you start up your VM. If they don't match, then you're going to have problems. We now have this line in our Dockerfile to build the base image:

RUN groupadd docker -g 800

This has solved the docker permissions issue for us.