WSL2 Cannot connect to the Docker daemon

Dutch77 picture Dutch77 · Mar 16, 2020 · Viewed 14.6k times · Source

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...

Answer

Patricio picture Patricio · May 6, 2020

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!!