71

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 am currently forced to use Windows for development, so I became a Microsoft insider member and installed ubuntu with WSL2 mode. Docker desktop supports integration for WSL2, so I tried it...

For a week it worked flawlessly. Today after a PC restart, I can't get docker running again. Ubuntu can see the injected binaries from Docker desktop, but it can't connect to windows hosted docker daemon anymore.

When I call in the WSL 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 windows 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...

Dave Mackey
  • 4,306
  • 21
  • 78
  • 136
Dutch77
  • 949
  • 1
  • 6
  • 10

17 Answers17

74

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

Dave Mackey
  • 4,306
  • 21
  • 78
  • 136
Patricio
  • 946
  • 7
  • 14
  • 11
    For me it worked after unsetting the old variable (removed from .bashrc). Thanks! – szegheo May 28 '20 at 15:07
  • 5
    My question is why the heck wasn't this clearly documented by Docker in the first place! – Matthew Marichiba Jun 01 '20 at 20:59
  • 2
    Thanks @Patricio your solution worked for me. My mistake was that I installed `docker-compose` inside WSL when Docker Desktop is already managing all that! – rachids Nov 03 '20 at 17:02
  • 2
    Following the instructions in the linked article worked for me. I had no `DOCKER_HOST` environment variable so I needed to follow the full instructions and install Docker Desktop Edge and it works great. – Bruno Girin Nov 27 '20 at 10:54
  • 2
    For me the key was uninstalling docker-ce and docker-ce-cli which was still present as i was using WSL v1 before. Best hint from the linked ressource: *"Some of the available tutorials or advices can be confusing because this time you shouldn't install or configure anything related to Docker under your WSL Linux distribution."* – maggie Jun 11 '21 at 12:35
56

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.

user2070077
  • 661
  • 4
  • 3
  • This happened to me when upgrading from the Stable to Edge release. – Greg Ferreri Aug 31 '20 at 13:00
  • Same for me. It happened when I added ubuntu 20 next to ubuntu 18 – fabiolune Nov 06 '20 at 17:11
  • 3
    same here.. * ticked it on again * run `wsl --shutdown` * started WSL2 distro again * still `docker ps` responds with `Cannot connect to the Docker daemon at...` Was a restart required for you guys? – spex66 Jan 21 '21 at 13:57
  • @spex66 i restarted and it still didn't work for me, did you have any luck? – vcapra1 Jan 27 '21 at 18:13
  • 1
    Happened to me when I moved my VM's storage file through wsl commands, i.e. unregistering it and importing it again removes it from docker integration. – Wasabi Feb 05 '21 at 15:12
  • 2
    Sneaky untick after docker update. Wsl could connect again after manual tick :/ – MattJ Sep 30 '21 at 14:00
  • 3
    This is exactly what happened to me. I ticked the `Ubuntu` integration back, and after waiting ~30s it worked again. Thanks a lot dude! – Elouan Keryell-Even Oct 19 '21 at 14:56
29

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

Settings > Resources > WSL Integration
amadesclaire
  • 411
  • 4
  • 10
  • 7
    This solved it for me __more than once__! If you've done this before, check it again. I found the checkbox for "my default WSL distro" was checked, but the switch for "Ubuntu" under "additional distros" went off. – Dave Nov 16 '22 at 09:16
14

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.

Yago Dórea
  • 336
  • 1
  • 3
  • 12
10

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.

Nagev
  • 10,835
  • 4
  • 58
  • 69
8

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

Willie Cheng
  • 7,679
  • 13
  • 55
  • 68
4

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

  • 2
    This is the only thing that worked for me, but only after I updated my Windows with "Check for Updates", on `1909 Build 18363.1256` - works like a charm – Meir Gabay Jan 10 '21 at 00:13
2

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
Harshit
  • 1,510
  • 19
  • 42
guobiao_cn
  • 65
  • 2
2

I had the same problem, the solution for me was to set my Ubuntu as the default wsl distribution: wsl --set-default Ubuntu

Nhamza
  • 21
  • 3
1

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
    
1

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

UltimaWeapon
  • 690
  • 9
  • 8
  • As well as this answer: `wsl -l` (in PowerShell) tells me `wsl default` is being reset to `docker-desktop-data (Default)` I repeatedly have to flick the switch in Docker Desktop under Settings -> Resources -> WSL Integration to "Enable integration with additional distros:". _or_ `wsl --set-default Ubuntu` in PowerShell – Dave Nov 16 '22 at 09:24
  • I say "repeatedly" because _I think_ these settings are lost when I restart Docker Desktop, or Windows. – Dave Nov 16 '22 at 09:25
0

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/

0

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

I found a 1.5 step fix. Go here, uncheck Enable, then Apply & restart button. Then check Enable, then Apply & restart button.

Docker now working fine in WSL2 Ubuntu.

enter image description here

lacostenycoder
  • 10,623
  • 4
  • 31
  • 48
0

The following sequence worked for me:

  1. Turn off all the WSL Integration checkboxes.
  2. Apply & Restart
  3. Turn back on either just the Default checkbox, or the specific distro slider, depending on whether it's the default or not.
  4. Apply & Restart
  5. Right-click the docker tray icon and Restart Docker.

It wasn't until step 5 that it actually started working.

I did have a container running at the time and "Apply & Restart" happened suspiciously fast, so I suspect it forgot to do the actual restarting part.

Miral
  • 12,637
  • 4
  • 53
  • 93
0

Try launching the docker service inside wsl2:

sudo service docker start

Verify the server is running

docker info
Pierre Louis
  • 308
  • 2
  • 11
-1

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

See this issue.

enter image description here

dan1st
  • 12,568
  • 8
  • 34
  • 67
oOMG
  • 1
  • 2
  • Moved to build `19582.1001`. Same issue :( – Dutch77 Mar 16 '20 at 18:55
  • you should upgrade to Docker Desktop WSL 2 backend https://docs.docker.com/docker-for-windows/wsl-tech-preview/ – oOMG Mar 17 '20 at 02:50
  • Did that. No luck. But it doesn't matter anymore. I deleted whole Ubuntu and started on clean slate and it's working. (for now). Thank you very much for reponses :) – Dutch77 Mar 17 '20 at 09:46