Docker is one of the leading platforms for building and running software containers. However, you may receive the “cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?” error message when using it. This post from MiniTool tells you how to get rid of the issue.
Docker is an open platform for developing, publishing, and running applications. Docker enables you to decouple your application from your infrastructure so you can deliver software quickly.
After installing it, you may receive the “cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?” error message. What causes the error? There are some possible reasons.
- Docker daemon is not running.
- Docker did not shut down cleanly.
- Lack of root privileges to start the docker service.
The following is about the solutions to the “cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?” error.
Method 1: Use Systemctl to Start the Docker Service
If you have fresh installed Docker on Ubuntu, the Docker service maybe not running. The systemctl command replaces the old SysV init system, which manages systemd services running on Linux systems. If you don’t have systemctl in your system, you can run the following command:
Tip: This method is only available for users who installed Docker using the APT package manager. If you installed Docker via SNAP, you can refer to Method 2.
Step 1: Open the terminal.
Step 2: Execute the following command one by one and press Enter after each one.
- sudo systemctl unmask docker
- systemctl start docker
- systemctl status docker
Then, you can check if the “cannot connect to the Docker daemon” issue has gone.
Method 2: Use Snap to Start the Docker Service
If you installed Docker with the Snap package manager, you can use the snap command to manage the docker daemon.
Step 1: Open the terminal.
Step 2: Execute the following command one by one and press Enter after each one.
- sudo snap start docker
- sudo snap services
Step 3: If the above command doesn’t work for you, try connecting the docker:home plugin as it doesn’t automatically connect by default. Once done, start the Docker service. Then, run the following command.
- sudo snap connect docker:home :home
- sudo snap start docker
Method 3: Clean a “Failed Docker Pull” and Start the Docker Service
In some cases, you might accidentally shut down Docker while pulling a container. This situation masks the docker.service and docker.socket files. Before proceeding to start docker, you need to unmask two unit files – docker.service and docker.daemon.
Step 1: Launch the Terminal and execute the commands below:
- systemctl unmask docker.service
- systemctl unmask docker.socket
- systemctl start docker.service
Step 2: Then, excute the following command:
- sudo su
- service docker stop
- cd /var/run/docker/libcontainerd
- rm -rf containerd/*
- rm -f docker-containerd.pid
- service docker start
Method 4: Start Docker for Users Without Root Privileges
You can also try to export the Docker host variable to localhost via port 2375. You need to execute the command – export DOCKER_HOST=tcp://localhost:2375.
Method 5: Reinstall Docker
If the above solutions are not working, it’s recommended to reinstall Docker. You can go to the official website to do that.
Final Words
These are common solutions to fix “cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?” in Docker. If you have any other useful methods to remove this error, leave a comment below to let us know.