7

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?

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • 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 – sgClaudia98 Oct 11 '22 at 00:44
  • 2
    this guide work for me, I just uninstall the docker and follow the digital ocean installation guide https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-22-04 – manoj prabhakaran Oct 17 '22 at 09:32
  • 2
    I am not sure but this solution works for me – manoj prabhakaran Oct 17 '22 at 09:36

3 Answers3

14

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/

ismailarilik
  • 2,236
  • 2
  • 26
  • 37
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/

Blackmac
  • 41
  • 4
2

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