Why am I getting a “Cannot connect to the Docker daemon” error in WSL2?

I know this may be outdated for the 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 the procedure to upgrade to WSLv2, 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 error, I followed instructions stated here: Link, and it worked.

Third, after some tests I think the missing change in the upgrade, was removing the DOCKER_HOST variable from shell’s start script.

SUMMARY: In my case, the procedure for a permanent fix should be the 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 by removing the setting of the 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!!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)