docker,

Resolve couldn't connect to docker daemon at http+docker //localhost - is it running?

Feb 08, 2022 · 2 mins read · Post a comment

Using Docker with a non-root user can cause issues connected with the Docker daemon. The Docker daemon binds to a Unix socket, so the Docker client will try to communicate to the daemon through that Unix socket. Even though the Docker daemon is running on your machine, you may face the following issue: couldn't connect to docker daemon at http+docker //localhost - is it running?

Prerequisites

  • Docker
  • sudo privileges

Solution

Step 1. The first step is to check if there is a Docker group created on the machine.

sudo cat /etc/group

If you cannot find the docker name in the output list you can create one with:

sudo groupadd docker

Step 2. But if there is a Docker group created the second step is to check whether the user is added to the Docker group or not. To check that execute the previous command cat /etc/group and if the user is not there you should add it.

sudo usermod -aG docker $USER

Step 3. In most cases, this is the step that fixes the issue. You need to check if the Docker group is added to the docker unix socket.

sudo ls -la /var/run/docker.sock

Output:

rw-rw---- 1 root 954 0 feb  8 15:33 /var/run/docker.sock

From the output above we can see that the user is root and the group is 954. So to fix the issue: couldn't connect to docker daemon at http+docker //localhost - is it running? we should add the docker group to the docker unix socket.

sudo chown root:docker /var/run/docker.sock

Step 4. Restart the Docker daemon.

sudo service docker restart

The error should be gone !!!

Conclusion

If you have any other workarounds don’t hesitate to put a comment below. On a side note, follow our official channel on Telegram.