How to fix Docker can't connect to daemon?

Better Stack Team
Updated on October 5, 2023

The error message "Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running?" typically occurs when the Docker client is unable to connect to the Docker daemon, either because it is not running or because it is not accessible to the client. Here are some steps you can take to fix this error:

Check if the Docker daemon is running by running the following command:

 
sudo systemctl status docker

If the Docker daemon is not running, you can start it using the following command:

 
sudo systemctl start docker

Check if the Docker daemon is accessible to the client by running the following command:

 
sudo docker info

If this command returns information about the Docker daemon, then the client is able to connect to the daemon and the error is likely caused by a permissions issue.

Check if the user running the Docker command is a member of the docker group. Only users in the docker group have permission to access the Docker daemon socket, which is located at /var/run/docker.sock. You can add a user to the docker group using the following command:

 
sudo usermod -aG docker <username>

Replace <username> with the username of the user you want to add to the docker group.

If the above steps do not resolve the issue, you can try restarting the Docker daemon and/or restarting the Docker service on the host system:

 
sudo systemctl restart docker
 
sudo service docker restart

Note that some Linux distributions may use a different command to manage services, such as systemctl instead of service. Check the documentation for your distribution to determine the correct command to use.

If none of these steps resolve the issue, it is possible that there is a more serious problem with the Docker installation or configuration. Check the Docker logs and consult the Docker documentation for more information.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github