WSL - Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Hi guys.

I’m using WSL on Windows 11 and installed Docker following instructions from Docker documentation - Install Docker Engine on Ubuntu | Docker Documentation

renatospaka@LINA-QG:~/dev$ docker version
Client: Docker Engine - Community
 Version:           20.10.9
 API version:       1.41
 Go version:        go1.16.8
 Git commit:        c2ea9bc
 Built:             Mon Oct  4 16:08:29 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

However, it is not working as per the following error:

renatospaka@LINA-QG:~/dev$ sudo docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

This is my WSL/Ubuntu setup:

renatospaka@LINA-QG:~/dev$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

Regards,
Renato

Hi, WSL does not have systemd. I have Windows 10, but I don’t think it is different in Windows 11.
Every time you start the WSL distro you have to start the docker service:

sudo service docker start

1 Like

Hi ,
correct, WSL does not have systemd, It is said on the Internet that it may also be because the docker service is not started, so I used another command:
sudo service docker start
and system shows: * Starting Docker: docker
it seem like run, I run this command:
sudo service docker status
but system show : * Docker is not running
I tried lots of time but it still not running…,can you help me, thank very much!
regards,
DB

It was just yesterday when I helped a colleague with the same issue. In his case WSL got an IP address colliding with the Docker network, so he had to change either the network of WSL or Docker. Changing Docker network was easier, so I recommended to do that. Create or edit /etc/docker/daemon.json and add an address pool setting:

{
  "default-address-pools": [
    {
      "base": "192.168.0.0/16",
      "size": 24
    }
  ]
}

It could also be:

{
  "default-address-pools": [
    {
      "base": "10.10.0.0/16",
      "size": 24
    }
  ]
}

or anything that is available in your network.

It is just an example. Make sure you don’t set a pool colliding with your local network. If you already tried to change the network of WSL, reset all the changes and reboot Windows so it can create the WSL network again.

The other, harder approach is creating a network adapter on the host which covers the IP addresses of Docker, so WSL can’t use that and it will choose an available IP address from 192.168.0.0/16.

Update

I realized that the described configuration above was not the solution of the issue, but it happened during the configuration which was required to fix the network. At a point, Docker could not start. You can check the log file:

sudo cat /var/log/docker.log