WSL icon indicating copy to clipboard operation
WSL copied to clipboard

WSL 2 docker client cannot reach Docker Desktop via tcp://0.0.0.0:2375

Open langlin opened this issue 7 years ago • 34 comments

  • Your Windows build number: 10.0.18932.1000
  • Ubuntu 18.04
$ lsb_release  -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:        18.04
Codename:       bionic
  • For Windows 10 FAST track until 10.0.18912.1000, I can use docker client in WSL 1 with Docker Desktop 18.01 - 18.09 simply through two configurations. In Docker Desktop: check "Expose daemon on tcp://localhost:2375 without TLS" In WSL 1: export DOCKER_HOST=tcp://0.0.0.0:2375

After upgraded to the build 18932 and WSL 2, docker client in WSL won't connect to Docker Desktop engine. Sample error.

$ docker image ls
Cannot connect to the Docker daemon at tcp://0.0.0.0:2375. Is the docker daemon running?

Still, the windows cmd side, docker client works as expected.

$ docker image ls
REPOSITORY                                                   TAG                 IMAGE ID            CREATED
        SIZE
dregistry.corp.xxxx.com:5443/de/nukl-bamboo           v1                  13cac1c2e659        2 weeks ago
        3.47GB
dregistry.corp.xxxx.com:5443/de/nukl-bamboo           latest              6378579fd96c        5 weeks ago
        730MB
dregistry.corp.xxxx.com:5443/de/rgp-bamboo            latest              43e7c044a2e3        6 weeks ago
        4.03GB
dregistry.corp.xxxx.com:5443/de/liteon723             latest              b8aa4d6c5888        8 weeks ago
        2.04GB
dregistry.corp.xxxx.com:5443/de/bezeq-dev             latest              0ac9e2c171ff        2 months ago
        2.1GB
ubuntu                                                       xenial              a3551444fc85        2 months ago
        119MB
dregistry.corp.xxxx.com:5443/de/nukl-build            <none>              a59151f7cb8b        2 months ago
        716MB
dregistry.corp.xxxx.com:5443/de/smart-gateway-build   latest              52b2485d5a31        6 months ago
        456MB

langlin avatar Jul 19 '19 12:07 langlin

It could be a local networking issue. Here are the ip addresses and the route table.

$ ipconfig

Windows IP Configuration

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::b837:aabe:a79a:66a1%35
   IPv4 Address. . . . . . . . . . . : 172.29.160.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (DockerNAT):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::98b:ff02:cfe4:4823%6
   IPv4 Address. . . . . . . . . . . : 10.0.75.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . : corp.xxxx.com
   Link-local IPv6 Address . . . . . : fe80::851d:67f0:5085:945d%5
   IPv4 Address. . . . . . . . . . . : 172.27.121.180
   Subnet Mask . . . . . . . . . . . : 255.255.255.248
   Default Gateway . . . . . . . . . : 172.27.121.177

Ethernet adapter Npcap Loopback Adapter:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::9df2:af9c:b5a8:d9d5%25
   Autoconfiguration IPv4 Address. . : 169.254.217.213
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (nat):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::9507:45cb:fcc5:c8ff%58
   IPv4 Address. . . . . . . . . . . : 192.168.0.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::8431:ce7:e67c:9239%88
   IPv4 Address. . . . . . . . . . . : 172.31.144.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :
$ route PRINT
===========================================================================
Interface List
 33...00 0e c6 a9 17 47 ......ASIX AX88179 USB 3.0 to Gigabit Ethernet Adapter
 35...00 15 5d 4b 11 03 ......Hyper-V Virtual Ethernet Adapter
  6...00 15 5d 30 1e 0f ......Hyper-V Virtual Ethernet Adapter #2
  5...18 66 da 29 de 6c ......Intel(R) Ethernet Connection (2) I219-LM
 25...02 00 4c 4f 4f 50 ......Npcap Loopback Adapter
 23...7c dd 90 8a 96 26 ......Microsoft Wi-Fi Direct Virtual Adapter #2
 21...7c dd 90 8a 96 27 ......Microsoft Wi-Fi Direct Virtual Adapter #4
 14...7c dd 90 8a 96 24 ......802.11n USB Wireless LAN Card #4
  1...........................Software Loopback Interface 1
 58...00 15 5d 0d 2a 73 ......Hyper-V Virtual Ethernet Adapter #3
 88...00 15 5d 72 c4 bf ......Hyper-V Virtual Ethernet Adapter #4
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0   172.27.121.177   172.27.121.180     25
        10.0.75.0    255.255.255.0         On-link         10.0.75.1    271
        10.0.75.1  255.255.255.255         On-link         10.0.75.1    271
      10.0.75.255  255.255.255.255         On-link         10.0.75.1    271
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    331
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    331
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    331
      169.254.0.0      255.255.0.0         On-link   169.254.217.213    281
  169.254.217.213  255.255.255.255         On-link   169.254.217.213    281
  169.254.255.255  255.255.255.255         On-link   169.254.217.213    281
   172.27.121.176  255.255.255.248         On-link    172.27.121.180    281
   172.27.121.180  255.255.255.255         On-link    172.27.121.180    281
   172.27.121.183  255.255.255.255         On-link    172.27.121.180    281
     172.29.160.0    255.255.240.0         On-link      172.29.160.1    271
     172.29.160.1  255.255.255.255         On-link      172.29.160.1    271
   172.29.175.255  255.255.255.255         On-link      172.29.160.1    271
     172.31.144.0    255.255.240.0         On-link      172.31.144.1   5256
     172.31.144.1  255.255.255.255         On-link      172.31.144.1   5256
   172.31.159.255  255.255.255.255         On-link      172.31.144.1   5256
      192.168.0.0    255.255.240.0         On-link       192.168.0.1   5256
      192.168.0.1  255.255.255.255         On-link       192.168.0.1   5256
   192.168.15.255  255.255.255.255         On-link       192.168.0.1   5256
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    331
        224.0.0.0        240.0.0.0         On-link   169.254.217.213    281
        224.0.0.0        240.0.0.0         On-link    172.27.121.180    281
        224.0.0.0        240.0.0.0         On-link         10.0.75.1    271
        224.0.0.0        240.0.0.0         On-link      172.29.160.1    271
        224.0.0.0        240.0.0.0         On-link       192.168.0.1   5256
        224.0.0.0        240.0.0.0         On-link      172.31.144.1   5256
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    331
  255.255.255.255  255.255.255.255         On-link   169.254.217.213    281
  255.255.255.255  255.255.255.255         On-link    172.27.121.180    281
  255.255.255.255  255.255.255.255         On-link         10.0.75.1    271
  255.255.255.255  255.255.255.255         On-link      172.29.160.1    271
  255.255.255.255  255.255.255.255         On-link       192.168.0.1   5256
  255.255.255.255  255.255.255.255         On-link      172.31.144.1   5256
===========================================================================
Persistent Routes:
  None

IPv6 Route Table
===========================================================================
Active Routes:
 If Metric Network Destination      Gateway
  1    331 ::1/128                  On-link
 25    281 fe80::/64                On-link
  5    281 fe80::/64                On-link
  6    271 fe80::/64                On-link
 35    271 fe80::/64                On-link
 58   5256 fe80::/64                On-link
 88   5256 fe80::/64                On-link
  6    271 fe80::98b:ff02:cfe4:4823/128
                                    On-link
 88   5256 fe80::8431:ce7:e67c:9239/128
                                    On-link
  5    281 fe80::851d:67f0:5085:945d/128
                                    On-link
 58   5256 fe80::9507:45cb:fcc5:c8ff/128
                                    On-link
 25    281 fe80::9df2:af9c:b5a8:d9d5/128
                                    On-link
 35    271 fe80::b837:aabe:a79a:66a1/128
                                    On-link
  1    331 ff00::/8                 On-link
 25    281 ff00::/8                 On-link
  5    281 ff00::/8                 On-link
  6    271 ff00::/8                 On-link
 35    271 ff00::/8                 On-link
 58   5256 ff00::/8                 On-link
 88   5256 ff00::/8                 On-link
===========================================================================
Persistent Routes:
  None

langlin avatar Jul 19 '19 13:07 langlin

You no longer need to use docker for desktop you simply run docker native within WSL 2. Since its now using Hyper-V and has a real kernel. You will need to remove the export DOCKER_HOST from your environment and start the docker daemon using systemctl.

Issue should be closed as a non-issue, it works perfectly in Ubuntu-18.04 I've tested it there myself.

david-dumke avatar Jul 19 '19 13:07 david-dumke

You no longer need to use docker for desktop you simply run docker native within WSL 2. Since its now using Hyper-V and has a real kernel. You will need to remove the export DOCKER_HOST from your environment and start the docker daemon using systemctl.

Issue should be closed as a non-issue, it works perfectly in Ubuntu-18.04 I've tested it there myself.

That is partially correct. If you then run the docker daemon inside WSL2 as a linux native docker, you will need to know how to connect to that Daemon from windows for a variety or reasons (people have DBs running inside docker that they want to connect to from WSL and from windows).

alexknips avatar Jul 19 '19 13:07 alexknips

You no longer need to use docker for desktop you simply run docker native within WSL 2. Since its now using Hyper-V and has a real kernel. You will need to remove the export DOCKER_HOST from your environment and start the docker daemon using systemctl. Issue should be closed as a non-issue, it works perfectly in Ubuntu-18.04 I've tested it there myself.

That is partially correct. If you then run the docker daemon inside WSL2 as a linux native docker, you will need to know how to connect to that Daemon from windows for a variety or reasons (people have DBs running inside docker that they want to connect to from WSL and from windows).

This may be true but I believe the post is talking simply about running a docker container not connecting a database to a docker container running in WSL2.

Edit: Typo :)

david-dumke avatar Jul 19 '19 15:07 david-dumke

You no longer need to use docker for desktop you simply run docker native within WSL 2. Since its now using Hyper-V and has a real kernel. You will need to remove the export DOCKER_HOST from your environment and start the docker daemon using systemctl. Issue should be closed as a non-issue, it works perfectly in Ubuntu-18.04 I've tested it there myself.

That is partially correct. If you then run the docker daemon inside WSL2 as a linux native docker, you will need to know how to connect to that Daemon from windows for a variety or reasons (people have DBs running inside docker that they want to connect to from WSL and from windows).

This may be true but I believe the post is talking simply about running a docker container not connecting a database to a docker container running in WSL2.

Edit: Typo :)

I was just explaining why some people still might want to run the docker container in Windows for Docker generally. Running docker in linux directly works generally but might not be what the original author of this issue wants to do. But they should just answer that themselves.

alexknips avatar Jul 19 '19 15:07 alexknips

You no longer need to use docker for desktop you simply run docker native within WSL 2. Since its now using Hyper-V and has a real kernel. You will need to remove the export DOCKER_HOST from your environment and start the docker daemon using systemctl. Issue should be closed as a non-issue, it works perfectly in Ubuntu-18.04 I've tested it there myself.

That is partially correct. If you then run the docker daemon inside WSL2 as a linux native docker, you will need to know how to connect to that Daemon from windows for a variety or reasons (people have DBs running inside docker that they want to connect to from WSL and from windows).

This may be true but I believe the post is talking simply about running a docker container not connecting a database to a docker container running in WSL2. Edit: Typo :)

I was just explaining why some people still might want to run the docker container in Windows for Docker generally. Running docker in linux directly works generally but might not be what the original author of this issue wants to do. But they should just answer that themselves.

Thanks, Alex and Strike. Indeed, as Alex stated, there are reasons for us to keep using Docker Desktop on Windows. Migrating all containers and volumes from Windows side to native Linux is not a one day job. Docker announced that they would move to WSL2 in future. I guess that there is a day that we will complete the migration. :-)

langlin avatar Jul 19 '19 18:07 langlin

If you then run the docker daemon inside WSL2 as a linux native docker, you will need to know how to connect to that Daemon from windows for a variety or reasons (people have DBs running inside docker that they want to connect to from WSL and from windows).

I am looking for how to access the docker host running in wsl2 from Windows and even remote desktop like macOS/Linux. Can I directly set the startup parameters in /lib/system/systemd/docker.service as in normal Linux and add -H tcp://0.0.0.0:2736? Then using some trick to access wsl2 docker host remotely(port forwarding and so on?)

fanvinga avatar Aug 06 '19 07:08 fanvinga

@fanvinga I have tried that with SysVinit procedure. For that, add DOCKER_OPTS="--host tcp://0.0.0.0:2375" line in /etc/default/docker file as root. Then start docker daemon in WSL with sudo service docker start. Now add set DOCKER_HOST=tcp://localhost:2375 in Windows side an run docker client.

For systemd, here are some discussions https://github.com/microsoft/WSL/issues/994#issuecomment-502055417.

Biswa96 avatar Aug 06 '19 09:08 Biswa96

@Biswa9 Sincerely thank you for your help, I set up the Windows inbound network firewall by the way, now I can use the docker client on my macOS to link the docker host in Windows WSL.

fanvinga avatar Aug 06 '19 09:08 fanvinga

There now is the docker desktop preview that can work together with a docker daemon running in WSL2

alexknips avatar Aug 08 '19 09:08 alexknips

Is there a fix for this issue that leaves Docker for Windows running?

l8nite avatar Sep 10 '19 17:09 l8nite

Didn't anyone watch this video about Docker Desktop Integration with WSL?

Biswa96 avatar Sep 10 '19 18:09 Biswa96

I have not spent the time to switch to WSL2

On Tue, Sep 10, 2019 at 11:03 Biswapriyo Nath [email protected] wrote:

Didn't anyone watch this video about Docker Desktop Integration with WSL https://www.youtube.com/watch?v=m_PpmELU_PM?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/microsoft/WSL/issues/4321?email_source=notifications&email_token=AANB3KT53VX5ZK2F6XZRGADQI7OO5A5CNFSM4IFFTSY2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6L7QWY#issuecomment-530053211, or mute the thread https://github.com/notifications/unsubscribe-auth/AANB3KWY4YPHM3OAQU6H7ZDQI7OO5ANCNFSM4IFFTSYQ .

l8nite avatar Sep 10 '19 18:09 l8nite

Didn't anyone watch this video about Docker Desktop Integration with WSL?

I tried. The accents are extremely difficult to parse out what they're saying. And the host stopping every 45 seconds to dumb down the presentation with quips like "So, magic." don't help AT ALL.

houstonhaynes avatar Sep 10 '19 18:09 houstonhaynes

@fanvinga I have tried that with SysVinit procedure. For that, add DOCKER_OPTS="--host tcp://0.0.0.0:2375" line in /etc/default/docker file as root. Then start docker daemon in WSL with sudo service docker start. Now add set DOCKER_HOST=tcp://localhost:2375 in Windows side an run docker client.

For systemd, here are some discussions #994 (comment).

I still got Cannot connect to the Docker daemon at unix:///var/run/docker.sock. And need start new session to solve this problem

rickywu avatar Sep 23 '19 04:09 rickywu

Anyone get this working? I have docker running using wsl context and can list my docker images from wsl2 and from windows cmd using 'docker image ls' but when i try view images using eclipse or kitematic from windows it doesn't find any images or containers. I'm trying to connect with localhost:2375. I have checkbox ticked to expose daemon on localhost:2375. I get the feeling kitematic and eclipse are looking for images in default windows context docker.

dean0bambin0 avatar Oct 06 '19 08:10 dean0bambin0

Anyone get this working? I have docker running using wsl context and can list my docker images from wsl2

I can't even get that special sauce working. What address did you use? I've tried the address in resolv.conf and localhost, didn't work.

jefferai avatar Nov 18 '19 22:11 jefferai

I think i have hit the same issue with running dockcross. Try running docker info as sudo. It seems to be the port that requires sudo privileges.

=== try setting as follows === sudo groupadd docker

sudo usermod -aG docker $USER

sudo chown root:docker /var/run/docker.sock

InsulinShock avatar Dec 24 '19 14:12 InsulinShock

After a couple of hours I finally solved the error Cannot connect to the Docker daemon at tcp://localhost:2375. Is the docker daemon running? and other similar problems which prevented to proper cooperation between WSL 2 and Docker Desktop WSL 2 backend.

The most common cause are the remains of old Docker approach under WSL 1. For example by set environment variable DOCKER_HOST=tcp://localhost:2375 under WSL for cooperating with Windows Docker option Expose daemon on tcp://localhost:2375 without TLS. If you used a different approach, it doesn't matter now. I suspect you have already tried a lot of advices so in my opinion the best you can do is to completely remove Docker from WSL and from Windows and all their residues. Then install latest versions of Windows Docker.

I assume you have already latest version of Windows 10 and WSL 2 with upgraded linux distro from WSL 1 to WSL 2.

How to completely remove Docker from Ubuntu (WSL)?

  1. As official Docker docs says:

    sudo apt-get remove docker docker-engine docker.io containerd runc

    You can add to this list also docker-ce and docker-ce-cli.

  2. Identify all docker packages what you have with dpkg -l | grep -i docker and remove if any still exists.

  3. Remove all residues:

    sudo rm -rf /var/lib/docker /etc/docker /etc/apparmor.d/docker /var/run/docker.sock /usr/local/bin/docker-compose /etc/docker
    
    sudo groupdel docker ~/.docker
    
  4. Be careful with this step. Probably you don't need it. It's for advanced users. Find all docker word occurrences and remove these you are sure of.

    sudo find / -name "*docker*"

  5. You should check all below files content for docker occurrences like ex. environment variable DOCKER_HOST=tcp://localhost:2375 which is residue from WSL 1 and its way to cooperate with Windows Docker by option Expose daemon on tcp://localhost:2375 without TLS.

    You can edit these files with Nano editor nano ~/.bashrc or Visual Studio Code code ~/.bashrc.

    ~/.bashrc
    ~/.bash_aliases
    ~/.bash_profile
    ~/.bash_login
    ~/.profile
    /etc/bash.bashrc
    /etc/profile
    

How to completely remove Docker from Windows?

  1. Firstly uninstall in normal way with Windows Apps & features panel.

  2. Remove all below if exists:

    C:\Program Files\Docker
    C:\ProgramData\Docker
    C:\Users\[USERNAME]\.docker
    C:\Users\[USERNAME]\AppData\Local\Docker
    C:\Users\[USERNAME]\AppData\Roaming\Docker
    

What next?

You should install latest version of Docker Desktop Edge from here and follow steps from official docs.

If everything goes fine you should have output from wsl -l -v like:

  NAME                   STATE           VERSION
* Ubuntu-18.04           Running         2
  docker-desktop         Running         2
  docker-desktop-data    Running         2

Some tutorials or advices can confuse you because this time you shouldn't install or config anything related with Docker under your WSL linux distro. It is very important. It should works out of the box after a few of simple steps from Docker docs.

Latest working versions (for today):

  • Windows 10 build 19041 from windows insider slow ring
  • WSL 2
  • Docker Desktop WSL 2 backend (v. 2.1.7.0)

TL;DR

  1. Get latest versions of Windows 10 (insider) and convert your WSL 1 distro to WSL
  2. Remove Docker and all its occurrences from WSL distro.
  3. Remove Docker and all its occurences from Windows.
  4. Install latest version Docker for Windows - "Docker Desktop WSL 2 backend".
  5. Follow steps from Docker docs and don't touch anything related to Docker in your WSL distro. It should work out of the box.

twistezo avatar Jan 11 '20 20:01 twistezo

@twistezo This is a good comment, https://github.com/microsoft/WSL/issues/4321#issuecomment-573351391. You should definitely post this on a blog or something.

I have a question for you: Have you tried using Alpine on WSL version 2?

My Ubuntu WSL 2 works just fine with the new in-WSL socket Docker Desktop publishes. But for the love of my life I can't get Alpine to connect to Docker Desktop's socket.

I wonder about other distros such as Debian.

AlexanderAllen avatar Feb 04 '20 16:02 AlexanderAllen