WSL2 Cannot connect to the Docker daemon WSL2 Cannot connect to the Docker daemon docker docker

WSL2 Cannot connect to the Docker daemon


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.


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 -vwsl.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         2C:\Users\xxxxx>wsl.exe --set-version Ubuntu-18.04 2Conversion 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