Wondering how to fix the error ‘Docker: Cannot connect to the Docker daemon’? Take a look at this blog.
Here at Bobcares, we have seen several causes for this error while troubleshooting Docker issues as part of our Docker Hosting Support for Docker users, web hosts, and online service providers.
Today we’ll take a look at the cause for this error message and see how to fix it.
What causes ‘Docker: Cannot connect to the Docker daemon’ error to occur
Here are the main causes for this docker error to occur.
1. The most common reason is that the docker daemon is not properly running on the host. You can check its status using the below command:
$ service docker status
2. In order to run any docker command, root privileges are necessary. In case, if you are running any docker command without prefixing it with sudo or without being in the docker group then you will receive this error.
This happens because the user that is trying to run the docker commands doesn’t have any permissions to interact with /var/run/docker.sock on that system.
Here is the complete docker error:
~~
docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?
See ‘docker run –help’.
~~
How we fix the error ‘Docker: Cannot connect to the Docker daemon’
Now let’s see the suggestions our Support Engineers provide our customers to resolve this error.
1. In case, if the docker daemon is not running properly then try starting the docker daemon. For that, you can run the below command.
$ service docker start
2. Ensure that you are prefixing the docker commands with sudo. However, if you are willing to avoid entering sudo while running any docker commands then add your username into the docker group:
$ sudo usermod -aG docker $(whoami)
Then activate the group by logging out of the server and logging in back as the same user. For that, run the below command.
$ newgrp docker
If you want to add a user into the docker group that you are not logged in as, then state that username explicitly by running the below command:
$ sudo usermod -aG docker username
[Need any further assistance in fixing Docker errors? – We’re available 24*7]
Conclusion
In short, this docker error occurs if the docker daemon is not running on the host or the user not having root privileges. Today, we saw the suggestions our Support Engineers provided to our customers to resolve this docker error.
0 Comments