8

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?

3
  • did you find a solution, same here, docker build is giving an error: "error getting credentials - err: exit status 1, out: no usernames for https://index.docker.io/v1/". But using sudo fixes it Commented Oct 11, 2022 at 0:44
  • 2
    this guide work for me, I just uninstall the docker and follow the digital ocean installation guide digitalocean.com/community/tutorials/… Commented Oct 17, 2022 at 9:32
  • 2
    I am not sure but this solution works for me Commented Oct 17, 2022 at 9:36

3 Answers 3

23

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/

1
  • I had a similar problem, in exactly the situation you described. I got disgusted with Docker Desktop and finally found the instructions to install what they now call Docker CE or Docker Engine. But I solved the problem as follows: rm -rf ~/.docker. Works fine now.
    – dougB
    Commented Aug 23 at 9:43
3

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/

0
3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.