Cannot connect to the Docker daemon
If you are just getting started with Docker there are a few different common error messages that will come up from time to time. One of these error messages is “Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?” . This specific message usually just means that the Docker daemon isn’t running. It could theoretically be caused by other things but more than likely it is just a case of the service needing to be started up. If it were a permissions issue you would see a different error. Really it means that the client can’t connect to the daemon. That could be for multiple reasons but is usually just caused by the daemon being down. Don’t want to read this entire page? Just run this sudo systemctl start docker. It will probably solve your problem.
This usually comes up when trying to run any Docker command such as this:
docker ps
The fix for: “Cannot connect to the Docker daemon”
You can check if the Docker daemon is running like this:
ps -ef |grep -i docker
If it isn’t you can start it like this:
sudo systemctl start docker
If it is running, then try restarting it like this:
sudo systemctl restart docker
This should solve your problem. Pretty easy right? Well unless it didn’t work. It probably did though because that is almost alwayst he problem. This comes up a lot and so most cases will be due to the daemon just not running. If it is still broken you are going to need to do a bit more work. This will either be a fun exercise or a headache depending on your situation. If you are being pressured to get something working ASAP then it might be a headache. If you are just tinkering around at home, then you’ve just stumbled upon an interesting exercise.
Edge Case
Sometimes people run into issues that require a bit more troubleshooting. One such instance can be seen HERE
I’ve never personally seen a case where just starting the daemon didn’t solve the problem associated with this specific error message but many people do. It is still an edge case though.
Many people on the above thread experienced this error and many of these people were unable to resolve it. People have reported this issue on multiple platforms including Debian, Ubuntu, and Windows.
People report seeing an error like this when they try to start the Docker daemon:
“A dependency job for docker.service failed. See ‘journalctl -xe’ for details.”
People have recommended using journalctl to examine the logs which raised even more question.
sudo journalctl -xe
sudo journalctl -xu
sudo journalctl -fu docker
Apparently Ubuntu 18.09.0 removed the docker socket file which causes an issue. One recommendation was to either place this back or remove the “-H fd://” option from the docker.service file. See HERE for more details.
Some people tried reinstalling Docker without any luck. Currently, as of now, your best bet is probably to re-install Docker with the latest package from Docker.
Another Possibility
Depending on your setup, there may be edge cases in which you receive this error message for other reasons. For example, let’s say you have centralized set of Docker servers but you choose to run the Docker client on your workstation. In this case you might be blocked by a firewall or you might be experiencing a network issue.
This could occur if you are running a command like this:
docker -H=remote-server1:2376 ps
If this is the case you are going to need to troubleshoot network connectivity between these two hosts which is another can of worms to open.