Are you trying to fix the error 'Docker: Cannot connect to the Docker daemon' ?
This guide is for you.
Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to fix Docker related issues.
In this context, we shall look into the causes of this error and how to get rid of it.
What triggers 'Docker: Cannot connect to the Docker daemon' error ?
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 to fix 'Docker: Cannot connect to the Docker daemon' error ?
Now let us see the steps 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