Linux – How to resolve the error "can't connect to Docker daemon"

LinuxOperating SystemOpen Source

It is one of the commonly known errors that the new users can get when trying to start Docker on a daemon process. This error usually comes up when you try to run the following command in your terminal

docker-compose build

The docker-compose in the above command is a tool that is used for running and defining multi container Docker applications.

The error looks something like this −

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

In order to make sure that you resolve this error, one approach is to make sure that post-installation steps are correctly followed.

Below, there are several commands shown that depict the correct way to set up the environment on both Mac OS X and other Linux distributions.

For Ubuntu/Fedora

The first step is to create the docker group with the help of the command shown below −

sudo groupadd docker

Now the next step is to add the user to the docker group

sudo usermod -aG docker currentUser

In the above command, replace the placeholder of currentUser with the user that you want to add to the group.

Next step is to log out from then log back in to make sure that Docker is running with the correct permissions.

Finally, you just need to start the Docker with the command shown below −

sudo service docker start

For Mac OS X

docker-machine start

The above command will start the virtual machine for Docker. Followed by the above command we need to get the environment variables, so run the command shown below −

docker-machine env

Finally, we need to run the below command to start the Docker service.

docker-machine start
raja
Published on 31-Jul-2021 12:16:54
Advertisements