WSL2 Cannot connect to the Docker daemon

Viewed 74139

here is my setup:

  • Windows 10 PRO - build 19041.153 - insider program - slow ring
  • Ubuntu 18.04LTS subsystem in WSL2 mode
  • Docker for desktop 2.2.0.4 - enabled WSL2 integration with my Ubuntu subsystem

I was currently forced to use Windows for development, so I became microsoft insider member and installed ubuntu with WSL2 mode. Docker desktop supports intergration for WSL2, so I tried it... For a week it worked flawlessly. Today after PC restart, I can't get docker running again. Ubuntu can see injected binaries from Docker desktop, but it can't connect to windows hosted docker daemon anymore.

When I call in subsys terminal docker info it returns

$ docker info
Client:
 Debug Mode: false

Server:
ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
errors pretty printing info

or with docker-compose up

ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?

If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

What I've tried already:

  • expose daemon without TLS with envs like DOCKER_HOST=localhost:2375, DOCKER_HOST=tcp://localhost:2375, DOCKER_HOST=127.0.0.1:2375, DOCKER_HOST=tcp://127.0.0.1:2375 => same result
  • uninstall Docker desktop and install previous version
  • turn off win firewall

I really, really need this to work. Thanks for any ideas. Weirdest thing is it worked yesterday and I didn't make any changes in system from then...

13 Answers

I know this may be outdated for present question, but this should save us precious time, especially when Windows 20H1=2004 is going to Production this month (May 2020).

  Operating System Version: Windows 10 Education (Same as Enterprise and a superset of Pro).
  Version: 2004
  Build (Version OS): 19041.264
  Others: Windows Feature Experience Pack 120.2202.130.0.
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Shell: WSL Terminal

First, i have installed WSL v1 previously, then executed procedure for upgrade to WSL v2, and this error shows up: "ERROR: Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running?".

Second, to fix that, I followed instructions stated here: Link, and it worked.

Third, after some tests i think the missing change in the upgrade, was remove DOCKER_HOST variable from shell's start script.

SUMMARY: In my case, the procedure for a permanent fix should be following STEPs:

  1. Test if it's your case unsetting DOCKER_HOST variable (See image below).

  2. If the error disappears with previous step, then time to fix changes removing setting of DOCKER_HOST variable in the shell's start script (In my case was $HOME/.bashrc).
    Commented this out:
      #export DOCKER_HOST=tcp://localhost:2375
      #export DOCKER_BUILDKIT=1

      NOTE: Also include DOCKER_BUILDKIT.

  3. Close and open the Terminal.

  Test in Step 1: enter image description here

Good luck!!

If it helps anyone else that is having this issue, for me it turned out that my subsystem was suddenly (and "on its own") ticked off in docker's RESOURCES > WSL INTEGRATION settings.

On the Docker Desktop app I had to manually enable my distro integration under

Settings > Resources > WSL Integration

I had installed Docker for Windows, as recommended, to use it with WSL 2 and that does indeed start the docker daemon for you. But I don't need all the fancy features it offers so removed it and was pleased to see about 4GB freed and no extra icon in the system tray.

Now if I need to run docker commands I just begin with:

sudo dockerd &

This way I can have it running on the background on the same shell. Note that in this example I have setup sudo without password. If a password is required, I can do sudo dockerd and open another terminal tab.

Although this works as a quick temporary solution I've seen it cause network issues so I would not recommend it, and prefer using a light VM instead.

I have found my issue was due to mis-reading instructions., fixed on my windows version 1909 and WSL 2 with the following commands on CMD:

wsl.exe -l -v
wsl.exe --set-version ${distro-name} ${wsl version}

example:

C:\Users\xxxxx>wsl.exe -l -v
  NAME                   STATE           VERSION
* Ubuntu-18.04           Running         1
  docker-desktop-data    Running         2
  docker-desktop         Running         2

C:\Users\xxxxx>wsl.exe --set-version Ubuntu-18.04 2
Conversion in progress, this may take a few minutes...
For information on key differences with WSL 2 please visit https://aka.ms/wsl2

That's it

I've tried soooo many things, and the stuff that worked for me, and no one ever mentioned to try:

(from Windows Powershell)

wsl --set-default <my-distro>

then and there, I could connect to docker without changing the DOCKER_HOST var.

1.open windows docker desktop --> Setting -->General --> Disable Expose daemon on tcp://localhost:2375 without TLS

img1

2.and then Go to Settings --> Resources --> WSL integration --> uncheck Enable integration with my default WSL distro and turn off integration with distro

img2

3.click apply and restart

4.then go to ubuntu try docker ps
docker ps if it does not work, continue to run the following command unset DOCKER_HOST to disable DOCKER_HOST

img3

Today I just tried it successfully

good luck to you

ISSUE: Cannot connect to the Docker daemon at tcp://127.0.0.1:2375

Powershell

wsl -l -v   # ALL DISPLAY "2"

Linux

unset DOCKER_HOST

/etc/init.d/docker restart

Restart Docker

windows docker restart
windows firewall off

Linux docker processes

docker ps

you can consider upgrading your version to 19582.1000 , it's work for me.

See this issue.

enter image description here

For whatever it's worth (this is an old thread). Maybe someone else is still desperately trying to solve this puzzle.

I have just stumbled over the solution in my case. I am running the following

  • docker desktop version 3.3.3
  • wsl 2
  • Fedora 33 Over and over again I ran into this issue "Cannot connect to the Docker daemon at unix:///var/run/docker.sock". Reinstalled, restarted, blablabla.

My ultimate error were access rights on /var/run/docker.sock, and I am running wsl under my personal user srw-rw---- 1 root docker 0 May 7 10:29 /var/run/docker.sock

So if I run as root (sudo docker info) or I put myself into group "docker" (sudo usermod -aG docker $USER) I'm all well. Please look here https://docs.docker.com/engine/install/linux-postinstall/

There is another very basic catch:

  • Ensure virtualization is enabled in the BIOS.
  • Please enable the Virtual Machine Platform Windows feature from the selection of additional Windows Features.
  • Now my motherboard is being very old, the BIOS does not support Enabling Virtualization.
  • Hence no solution will work for me.
  • WSL Version 1 or 2 will come from Windows Update automatically.

After hours, my docker worked using following method.

  1. Go to docker desktop --> Setting -->General --> Disable Expose daemon on tcp://localhost:2375 without TLS

  2. Go to Settings --> Resources --> WSL integration --> uncheck Enable integration with my default WSL distro and turn off integration with distro

  3. Restart Docker desktop

  4. Now in WSL,

    unset DOCKER_HOST
    
  5. Now try,

    docker ps
    

The accepted answer is mostly correct. However, I wanted to specify that when using WSL2 + Docker Desktop:

  • You must unset DOCKER_HOST which was previously needed in WSL1
    • Mine was defined in ~/.bashrc in both Windows and WSL.
    • Delete in both. Also delete in Windows env variables via Control Panel.
    • Check with env | grep -i docker to make sure it's gone.
  • You must also set the correct settings in Docker Desktop
    • Uncheck Export daemon on tcp://localhost:2375 without TLS
    • Check Use the WSL2 based engine
    • Resources -> WSL Integration -> Check Enable integration with my default WSL distro

Now, you can do a simple docker info to check if you're running the same server version in WSL and in Windows (Powershell).

Related