16

I get this error in Ubuntu in vscode and I can't see my images in vscode.

I run sudo docker ps -a and everything is OK on terminal!

What should I do to solve this problem?

enter image description here

enter image description here

Milad
  • 335
  • 1
  • 2
  • 13

9 Answers9

9

I think it can be because your user is not in the docker group. Easily check the list of your user's groups using: groups <user>

And check in the output if you can see "docker".

If not, simply add the user to the docker group by typing:

sudo usermod -aG docker ${USER}

Don't forget to restart the VS Code and the system if necessary.

themozel
  • 312
  • 3
  • 11
3

With the docker extension installed, workaround for me (on Mac) was:

  • (cmd-shift-p)
  • Go to "Preferences: Open Workspace Settings"
  • at the top of the settings, search for "docker path"
  • enter Absolute path to docker client executable (in my case "/usr/local/bin/docker")

setting for path to docker client executable

Hope this helps someone.

ndo
  • 96
  • 7
2

In you installed VS Code with the flatpak package manager (For example on PopOS) it will not detect docker

Fuji
  • 28,214
  • 2
  • 27
  • 29
2

After an upgrade I got the permission denied. Doing the steps of 'mkb' post install steps don't have change anything because my user was already in the 'docker' group; I retry-it twice any way without success.

After an search hour this following solution finaly worked :

sudo chmod 666 /var/run/docker.sock

Solution came from Olshansk.

Look like the upgrade have recreate the socket without enough permission for the 'docker' group.

Problems

This hard chmod open security hole and after each reboot, this error start again and again and you have to re-execute the above command each time. I want a solution once and for all. For that you have two problems :

    1. Problem with SystemD : The socket will be create only with owner 'root' and group 'root'.

    You can check this first problem with this command :

      ls -l /lib/systemd/system/docker.socket
    

    If every this is good, you should see 'root/docker' not 'root/root'.

  • 2 ) Problem with graphical Login : https://superuser.com/questions/1348196/why-my-linux-account-only-belongs-to-one-group

    You can check this second problem with this command :

      groups
    

    If everything is correct you should see the docker group in the list. If not try the command

      sudo su $USER  -c groups
    

    if you see then the docker group it is because of the bug.

Solutions

If you manage to to get a workaround for the graphical login, this should do the job :

sudo chgrp docker /lib/systemd/system/docker.socket
sudo chmod g+w /lib/systemd/system/docker.socket

But If you can't manage this bug, a not so bad solution could be this :

sudo chgrp $USER /lib/systemd/system/docker.socket
sudo chmod g+w /lib/systemd/system/docker.socket

This work because you are in a graphical environnement and probably the only user on your computer. In both case you need a reboot (or an sudo chmod 666 /var/run/docker.sock)

1

I had to create docker group for themozel's solution to work.

Here is what worked for me:

Creates docker group

sudo groupadd docker

Add your user to the docker group

sudo usermod -aG docker $USER

  • Basically the docker group should be created automatically when you install docker. But if it is not there, then yes it should be done manually. Thanks for the tip. – themozel Jul 19 '22 at 13:27
1

The problem is docker is running as root but vs code trying to connect in user.

I am also having this problem. I solved this problem with install the Docker Engine

Delete the docker completely

sudo apt-get remove docker docker-engine docker.io containerd runc

Then install the Docker Engine https://docs.docker.com/engine/install/

Blackmac
  • 41
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 25 '22 at 08:51
1

I was able to fix this by restarting the remote machine. I also just installed Docker on an Azure instance and was starting development on a project. I added my user to the Docker group but they were somewhere/somehow logged in and I couldn't get Visual Studio code to understand the user was in the Docker group. I was doing the same, testing in the command line with another terminal session and the user was in the group, could call docker ps and so forth. Just not in Visual Studio code.

I restarted the remote machine, reconnected with VS Code and was able then to connect to Docker in VS Code which is going to make my life a lot easier.

(I can't post the screenshots because I lack the reputation)

0

If you installed VS Code from Flatpack (and probably from similar tools) it runs in its own isolated environment with its own shell and, in my case, my set of groups was different from normal - while in a normal shell I was a member of the "docker" group, in the VSC terminal I wasn't. There can be a number of issues related to this isolated installation. The solution is simple - uninstall your VSC and install it from a normal repository, just follow the instructions for your distribution.

0

I had the same problem in VS Code... I am using Ubuntu 20.04.6 LTS and this solution was good for me:

1 - Open the file /usr/lib/systemd/system/docker.service:

sudo nano /usr/lib/systemd/system/docker.service

2 - Append the following lines to the bottom of the Service section:

SupplementaryGroups=docker    
ExecStartPost=/bin/chmod 666 /var/run/docker.sock

3 - Restart the Docker daemon:

systemctl daemon-reload
systemctl restart docker.service

This article helped me with the resolution