Although an excellent tool for application building and deployment, Docker can be a victim of errors like any other software. Recently, an error message “Cannot connect to the Docker Daemon at unix:///var/run/docker.sock” was reported by many users.

Although its roots can seem confusing to locate, the problem at its core is created by an overload of docker commands. However, there can be more than one reason for such an error. So, buckle up, read the reasons, and follow their appropriate solutions to get your docker app up and running in no time.

What’s Causing the Error

As mentioned earlier, the most probable reason for this error is when numerous commands are thrown at docker to perform, such as docker run, docker info, docker pull, stop, etc. However, this isn’t the only reason; it may be that Docker Daemon has stopped running at all, in which case you’d need to launch it with ‘systemctl’.

If not for the above reason, it could be that your Docker Application doesn’t shut down properly, which can cause problems when you try to run it the next time. Other than that, a lack of root privileges can also be a valid reason.

While these reasons may seem difficult to understand, they require only a few simple steps to eradicate. So, without fretting over this any further, see which fix from below solves the problem for you.

Fix #1: Launch Docker with Systemctl

As mentioned earlier, when docker stops running, a simple approach is to launch the service with systemctl. Usually, this happens when you’re trying to run docker for the first time after installation.

The systemctl command’s main purpose is to renew the SysV init system, managing the system services. So, this is the best option to use to fix this problem. However, if your system does not have systemctl, then follow the steps given below:

Launch the terminal and type in the following command: ‘sudo systemctl unmask docker’.
After the docker is unmasked, launch the docker daemon service via the following command: ‘systemctl start docker’.
This should start the service and solve the problem, but double-checking it doesn’t hurt. So, type the following command to see the docker status: ‘systemctl status docker’.

Fix #2: Clean and Restart Docker Service

As mentioned earlier, a failed service shutdown during some docker operation makes files become masked. This affects the docker daemon service connection.

First, open terminal and execute the following commands:

  • systemctl unmask docker.service
  • systemctl unmask docker.socket
  • systemctl start docker.service

After that, see if the problem is fixed. If not, then type in the following commands in the terminal to delete the Containerd directory:

  • sudo su
  • service docker stop
  • cd /var/run/docker/libcontainerd
  • rm -rf containerd/*
  • rm -f docker-containerd.pid
  • service docker start

Once the commands are executed, see if the docker daemon problem still persists. If it does, head over to the next fix we’ve got for you.

Fix 3: Launch Docker Service with SNAP (for SNAP installation)

If you installed the docker application via SNAP, and not through APT package manager, you need to follow the steps below to run the Docker service.

Launch the terminal.
Type in the following command and hit Enter: sudo systemctl unmask docker
After that, type in the following command to ensure your files aren’t masked: $ systemctl list-unit-files
Once that is done, try running the docker service via the following command: systemctl start docker
Then, to make sure the service is up and running, type in the following command and execute it as well: systemctl status docker
Conclusion

The error message “Cannot connect to Docker Daemon at unix:///var/run/docker.sock” may seem startling and difficult to handle initially, but the problem is quite simple. Hopefully, the fixes we’ve provided have worked out for you. If none of them are working out, you should reinstall the service from scratch and then try to apply the fixes above.

Protect Your Identity, Get NordVPN

Black Friday sale up to 68% off.

Leave a Reply