docker,

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

Feb 08, 2022 · 2 mins read · Post a comment
Resolve couldn't connect to docker daemon at http+docker //localhost - is it running?

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

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

Example 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.