[FIX] Cannot Connect to the Docker Daemon at ‘unix:///var/run/docker.sock’
When you see the error message “Cannot connect to the Docker daemon at ‘unix:///var/run/docker.sock’“, it usually means that commands like `docker run` or `docker ps` won’t work. As a result, you can’t interact with Docker containers. This error occurs because the Docker client can’t connect with the Docker daemon, which is the core program that handles all Docker operations on your computer.

The most common cause of this problem is that the Docker service isn’t running on your system. Other possible reasons include not having the necessary permissions to access the Docker socket, issues with how Docker is installed, or problems with the `docker.sock` file itself.
Now that you have an idea of the possible causes, let’s go through some practical solutions.
1. Start the Docker Service with systemctl
The first thing to check is whether Docker is running. The `systemctl` utility lets you start and manage system services. If Docker isn’t active, the Docker client won’t be able to communicate with the main Docker process, which causes this error. Running the `systemctl start docker` command starts the Docker service and should fix the problem if it was simply inactive.
- Open the Terminal and run the following command first to unmask Docker:
sudo systemctl unmask docker
If you try to start Docker while it’s masked, you’ll see the error ‘Failed to start docker.service: Unit is masked.’ Masking is like a stronger way of turning a service off—it stops the service from starting completely. If you want to see the state of all unit files on your system, use systemctl list-unit-files.
- Once Docker is unmasked, you can start the Docker daemon with this command. The Docker daemon is the background service that manages images and containers and processes Docker’s API requests.
sudo systemctl start docker
- To check if Docker is running, enter this command. It will show you the current status of the Docker service:
sudo systemctl status docker
- As you can see in the image above, you should now see Docker is active and running.
2. Clean Up a ‘Failed Docker Pull’ and Start Docker Service
Sometimes, if a Docker pull fails, it can leave behind incomplete files that prevent the Docker daemon from starting correctly. Removing these leftover files gives Docker a fresh start. Restarting the Docker service afterwards helps clear up any issues that stuck or broken files can cause.
- Open your Terminal and enter these commands:
sudo systemctl unmask docker.service sudo systemctl unmask docker.socket sudo systemctl start docker.service
If you continue to see the error after running these commands, you should delete leftover files in the Containerd directory, then try starting Docker again. Containerd, which became part of Docker in version 1.11, helps manage Docker containers directly from the background.
- Stay in the Terminal and run these commands—note that you’ll need your root password:
sudo su service docker stop cd /var/run/docker/libcontainerd rm -rf containerd/* rm -f docker-containerd.pid service docker start
3. Start Dockerd (Docker Daemon) Service Directly
Dockerd is the main program (daemon) that runs in the background and handles all Docker tasks. In some cases, starting Dockerd directly can help, especially if using the `systemctl` command does not work for your system.
- Open Terminal and use this command to start the Docker daemon directly:
sudo dockerd

4. Start Docker with the Service Command
Manually starting Docker can make sure the service is running. You can use the `sudo service docker start` command to start Docker, which is useful if Docker didn’t start automatically after a system reboot.
- Open your Terminal and run:
sudo service --status-all sudo service docker start

5. Start the Docker Service with Snap
If you installed Docker using Snap, you need to make sure the Snap-managed Docker service is running. Snap sometimes requires you to start or connect services yourself. Use `sudo snap start docker` to make sure the Docker daemon is running as intended.
- Open Terminal and run this command to start Docker:
sudo snap start docker
- To check if Docker started properly with Snap, use:
sudo snap services
- This will list all running snap services:
- If Docker still won’t start, try connecting the docker:home plug, which isn’t always connected automatically. Then, restart Docker.
- Open Terminal and execute:
sudo snap connect docker:home :home sudo snap start docker
6. Start Docker for Users without Root Privileges
This error can also occur if you don’t have enough permission to access ‘unix:///var/run/docker.sock’. You can temporarily work around this by exporting the Docker host variable to use the local network interface via port 2375.
- Open the Terminal and run:
export DOCKER_HOST=tcp://localhost:2375
7. Reinstall Docker
Sometimes, issues with how Docker was installed—like corrupted files or wrong settings—might keep the Docker daemon from running correctly. Reinstalling Docker puts everything back into its default state and can fix problems caused by broken or conflicting setups.
- After reinstalling Docker, make sure the service is running by using:
sudo service docker start
This command will start Docker and often fixes issues when the program isn’t active, especially after a computer restart or if Docker failed to launch automatically.
- Because the Docker daemon controls all containers and images, making sure it is running restores the connection between the Docker client and daemon, which can fix errors caused by the service being stopped or inactive.