Docker Desktop: ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

I followed the instructions Ubuntu | Docker Docs on a new virtual machine.
Next in step 3 Part 1: Containerize an application | Docker Docs after running the command
docker build -t getting-started .
an error is issued
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Information about the environment:
Ubuntu 22.04
avauser@web:~/getting-started-app$ docker compose version
Docker Compose version v2.23.0-desktop.1
avauser@web:~/getting-started-app$ docker --version
Docker version 24.0.7, build afdd53b
avauser@web:~/getting-started-app$ docker version
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Client: Docker Engine - Community
Cloud integration: v1.0.35+desktop.5
Version: 24.0.7
API version: 1.43
Go version: go1.20.10
Git commit: afdd53b
Built: Thu Oct 26 09:07:41 2023
OS/Arch: linux/amd64
Context: default

Similar topics are not suitable for these reasons:

1. https://forums.docker.com/t/error-cannot-connect-to-the-docker-daemon-at-unix-var-run-docker-sock-is-the-docker-daemon-running/115408
Not suitable, since Docker Engine is considered there
2. https://forums.docker.com/t/cannot-connect-to-the-docker-daemon-at-unix-var-run-docker-sock-is-the-docker-daemon-running/130002
Not suitable, since Docker Engine is considered there
3. https://forums.docker.com/t/cannot-connect-to-the-docker-daemon-at-unix-var-run-docker-sock-is-the-docker-daemon-running/57372
Not suitable, since it runs under Windows
4. https://forums.docker.com/t/docker-cannot-connect-to-the-docker-daemon-at-unix-var-run-docker-sock-is-the-docker-daemon-running/79657
Not suitable, as it runs under DockerHub
5. https://forums.docker.com/t/cannot-connect-to-the-docker-daemon-at-unix-var-run-docker-sock-is-the-docker-daemon-running-2-0/64828/5
Not suitable, since docker-compose was installed

Hi. This is an English community forum, please, edit your post and translate the non-English parts of your message to English, otherwise your post could be removed. Thank you!

Hi!
It was translated.

If you are using the Desktop, the context shouldn’t be default but “desktop-linux”. It could also be default, but if you installed docker engine as well, and you don’t have the docker group and don’t use sudo, you can’t access the docker socket.

Try

docker context use desktop-linux

and try docker commands again.

Many people misunderstood the installation guide and installed the engine as well, not just the client. Docker Desktop needs only the client.

1 Like

I had the same issue with the same configuration. I’ve solved this in this manner:

Issue : Cannot load builder default: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

  • Step 1. Verify context, it should be dektop-linux
    $ docker context show
  • Step 2. Change the context if needed
    $ docker context use desktop-linux
  • Step 3. Find the docker.sock file location
    $ docker context ls
  • Step 4. Create symlink
    $ sudo ln -s /home/<user>/.docker/desktop/docker.sock /var/run/docker.sock
3 Likes

thank you so much for this!
the error was solved on my machine.

This was very helpful to solve my problem although mine was slightly different. I initially installed the engine, then after installing docker-desktop I could not connect to the daemon with either sudo or my user. I had to uninstall desktop (other problems still debugging) and still couldn’t run the commands with sudo until I discovered this post. My “default” context points to the proper socket. After using “sudo docker context use default” I could run the commands as root. The desktop-linux context was a stale context that is no longer valid after purging desktop.

3 posts were split to a new topic: Cannot connect to the Docker daemon in Rancher Desktop

I am getting this error on trying to create a symlink:
ln: unix:///var/run/docker.sock: No such file or directory

Which is true as nobody used unix:// in a symlink command. You wouldn’t try to use http:// either. I also don’t see why creating a symlink would be necessary. You change context and you are done. Symlink could only be necessary if you want multiple contexts using the same socket.

1 Like

Thanks for the reply. I got this now. It was actually an issue with the Intellij Idea IDE which wasn’t picking the default context. This got resolved once I switched back to desktop-linux as default builder in docker desktop

This resolved my situation. For whatever reason, the symlink was not there.

The reason is that the symlink doesn’t have to be there. Details in my previous post.