manoj prabhakaran
manoj prabhakaran

Reputation: 133

Docker not working without sudo in Ubuntu, referencing .docker/desktop directory

On an Ubuntu 22.04 system, whenever I run any docker command, it prints out an error:

Cannot connect to the Docker daemon at unix:///home/<username>/.docker/desktop/docker.sock. Is the docker daemon running?

If I check with systemctl status docker, it shows that the Docker daemon is running, however.

Running sudo docker ... works, but I'd prefer to not prefix every Docker command with sudo. I've tried many of the approaches in How to fix docker: Got permission denied issue, including adding my user to the docker group and relaxing the permissions on /var/run/docker.sock, but I still get this error.

What might be causing this?

Upvotes: 10

Views: 5460

Answers (3)

buvanesh buvhi
buvanesh buvhi

Reputation: 61

We should not install both the Docker engine and the Docker Desktop. If you install docker-engine alone the problem won't occur.

Upvotes: 3

ismailarilik
ismailarilik

Reputation: 2366

If you installed Docker Desktop first, then removed it and installed the Docker Engine, you may need to switch the Docker context with this command:

docker context use default

Because Docker Desktop switches context before startups and shutdowns not to interfere Docker Engine. So context might be kept incorrectly after removing Docker Desktop. A related article: https://www.howtogeek.com/devops/how-to-troubleshoot-cannot-connect-to-the-docker-daemon-errors/

Upvotes: 26

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: 3

Related Questions