Solution to cannot connect to the docker daemon Error
There are two reasons you get the "cannot connect to the docker daemon" error message when try to run docker command.
One reason is docker service is not running. So first of all make sure that docker service is running.
systemctl is-active docker
If service is not active, then start and enable the docker service.
systemctl start docker
systemctl enable docker
Run Docker command as non root user
Another reason could be you are trying to run the docker command as non root user.
Non root users can run the docker command if you add the user to the docker group.
Create the Docker group if it is not there already:
sudo groupadd docker
Restart the Docker Service:
sudo systemctl restart docker
Add the user to the docker group:
sudo usermod -a -G docker username
Now re login to the user account and try to run the docker command without sudo in front.
This time you should not get the error message "Cannot connect to the Docker daemon. Is the docker daemon running on this host?".