Docker

How to Fix “Docker can’t connect to docker daemon”? Error

Docker is a platform that is used by developers to containerize or isolate the program, project, or software. It is basically used to build, run and deliver applications and software in executable packages. For this purpose, Docker uses different components and Docker daemon is one of them. The Docker daemon is basically responsible to manage and run the images and container on the host. It gets instructions from the Docker client and then takes action on the server.

However, sometimes Docker users may face difficulty or may encounter errors like “Docker can’t connect to docker daemon” while executing any Docker command as shown below:


This article will demonstrate how to fix the “Docker can’t connect to docker daemon” error.

How to Fix the “Docker can’t connect to docker daemon” Error?

Docker is not connecting to Docker Daemon error occur due to different reasons such as the “docker” user group is not created on Linux, the Docker engine is not started or Docker is not properly installed.

To fix the “Docker can’t connect to Docker Daemon” error, try out the following fixes:

Fix 1: Add “docker” Usergroup in Linux

Sometimes, when users installed the Docker for the first time or change the Docker version, they may encounter an error “Docker can’t connect to docker daemon” while executing any Docker command. This error mostly occurs in Linux distribution, when “docker” is not added in the Linux user group. It is necessary to add the “docker” user in Linux as every Docker command starts with “docker”.

To add the new user “docker” in Linux, simply use the given command:

sudo usermod -aG docker $USER

 

After that, again execute the Docker command and verify whether the stated error is resolved or not.

Fix 2: Restart Docker

The “Docker can’t connect to docker daemon” error usually occurs on Linux systems. As on Windows, when the Docker Desktop application launched, the Docker engine automatically starts executing. In case, if the Docker is not started properly, then the user may face the stated error.

To fix the specified error, try to restart Docker using the following steps.

Step 1: Launch Powershell as Administrator

First, launch the Powershell as an administrator from Windows “Startup” menu:


Step 2: Stop Docker

Next, execute the “sc stop docker” command to stop the Docker service on Windows:

sc stop docker

 

Step 3: Restart Docker

Next, restart the Docker service using “sc start docker”:

sc start docker

 

Alternatively, to restart Docker if the Docker desktop is already running, click on the below-highlighted drop-up icon. Then, right-click on the “Docker” icon, and choose the “Restart” option from the appeared context menu:


To restart Docker on the Linux operating system to fix the stated error, utilize the “systemctl restart docker” command with “sudo” user privileges:

sudo systemctl restart docker

 

After that, try to execute any docker command such as the “docker run” command, and verify whether the stated issue is resolved or not.

Fix 3: Check the Docker Desktop Status

If the Docker desktop on Windows and Docker on Linux is not executing or running, the “Docker cannot connect to Docker Daemon” error occurs. To check the Docker status, again click on the “drop up” icon from Taskbar. Right-click on the “Docker” icon and verify whether the Docker is running or not from highlighted option:


On Linux distribution check the Docker status using the provided command:

sudo systemctl status docker

 
The output shows that the Docker is currently inactive:


To activate or start the Docker on Linux, simply utilize the “systemctl start docker” command:

sudo systemctl start docker

 

Again, check the Docker status on Linux:

sudo systemctl status docker

 
The output shows that Docker is successfully running on Linux distribution:


Now, execute the Docker command and check if the issue is resolved or not.

Fix 4: Check Docker is Properly installed

Sometimes, when Docker is not properly installed on the system, the users may encounter the “Docker can not connect to docker daemon” error. To fix this issue, try to reinstall the Docker application. To install Docker on Windows, follow our associated article.

In order to install Docker on Linux distribution like Ubuntu, utilize our attached article.

Fix 5: Check Docker Daemon Accessibility

As we have already explained the “Docker can’t connect to docker daemon” usually occurs on Linux. Because on Linux, the Docker daemon is running as a separate service. However, on Windows Os, when the “Docker Desktop” is launched, the Docker engine will automatically start.

To check if the Docker Daemon is running or accessible on a Linux system, first, reload the Docker Daemon and restart the Docker service. After that execute the “sudo netstat -lntp | grep dockerd” command. For demonstration, go through the listed steps:

Step 1: Restart Docker Service

First, restart the Docker service by utilizing the “systemctl restart docker.service” command:

sudo systemctl restart docker

 

Step 2: Install Net Tools

Sometimes, the net tools are not installed on the system to manage the subsystem of the network on the Linux kernel. To install net-tools, utilize the following command:

sudo apt install net-tools

 

Step 3: Check Docker Daemon Accessibility

Next, check the Docker daemon accessibility on the Linux system using the “netstat” command as mentioned below:

 sudo netstat -lntp | grep dockerd

 
If the output shows some port and IP addresses it means dockerd is configured remotely. If any error occurs or warning, it means the dockerd is not working properly. Then, try to reinstall docker and configure dockerd:


This is all about resolving the “Docker can’t connect to docker daemon” error.

Conclusion

The “Docker can’t connect to docker daemon” error usually occurs when the Docker daemon is inactive, or the “docker” user is not added to the Linux user group. To fix the stated error, add the “docker” Usergroup in Linux, restart Docker, check Docker is properly installed, and check Docker Daemon accessibility. This article has provided the solutions to fix the “Docker can’t connect to docker daemon” error.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.