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
Answers
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
Then install the Docker Engine
https://docs.docker.com/engine/install/
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:
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/
We should not install both the Docker engine and the Docker Desktop. If you install docker-engine alone the problem won’t occur.