Milad
Milad

Reputation: 444

Failed to connect. Is Docker running? (Vs Code)

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

Upvotes: 25

Views: 46266

Answers (10)

chewbii
chewbii

Reputation: 31

I guess docker use unit socket communicate, which belongs to root user, and ordinary users need to use sudo to enable root permissions.

sudo groupadd docker          
sudo gpasswd -a $USER docker  
newgrp docker 

or

simply sudo chmod 777 /var/run/docker.sock

both do not forget reboot,

this methods work for me.

Upvotes: 3

Fuji
Fuji

Reputation: 29824

If you installed VS Code with the flatpak package manager (For example on PopOS) it will not detect docker. There is a Ubuntu deb VSCode package available

Upvotes: 4

Richard Ambrosio
Richard Ambrosio

Reputation: 1

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

Upvotes: 0

Mountain Tran
Mountain Tran

Reputation: 301

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)

Upvotes: 17

Sergey Podushkin
Sergey Podushkin

Reputation: 507

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.

Upvotes: 0

Joseph Henzi
Joseph Henzi

Reputation: 21

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)

Upvotes: 2

ndo
ndo

Reputation: 355

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.

Upvotes: 19

Blackmac
Blackmac

Reputation: 41

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/

Upvotes: 1

Alexander Shapiro
Alexander Shapiro

Reputation: 41

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

Upvotes: 1

themozel
themozel

Reputation: 492

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.

Upvotes: 12

Related Questions