Networking problems with WSL2 and Docker Desktop for windows [closed]
Asked Answered
W

4

14

TL;DR

It seems I'm constantly running into networking problems when using WSL2 and Docker Desktop for Windows.

Normally, I can access a port started from a WSL2 instance ("distribution" in WSL2-speak) from inside Docker containers, by finding the IP address of the WSL2 instance, and referencing to that IP address from inside the containers. But today that doesn't work for some reason. I'm getting used to rebooting when I run into WSL2+DockerDesktop problems, but now I'd like to finally understand what is actually wrong.

I'm pretty sure that when I reboot in a moment, all will be fine and dandy.

Do you have an idea on how to debug something this?

I also have a corporate Forticlient VPN that could be messing this up. But I have no choice in that matter... ;-(

Details

I find the IP with:

WSL2:» ip -br a
lo               UNKNOWN        127.0.0.1/8 ::1/128 
bond0            DOWN           
dummy0           DOWN           
sit0@NONE        DOWN           
eth0             UP             172.26.183.209/20 fe80::215:5dff:fef9:cc5c/64 

So the WSL2 machine's IP address is 172.26.183.209.

So now that I have a web server listening on port 8080 in a process my WSL2, it can be accessed with http://172.26.183.209:8080, as confirmed by nmap and curl from WSL2:

WSL2@~» nmap -Pn -p 8080 172.26.183.209            
Starting Nmap 7.80 ( https://nmap.org ) at 2020-12-23 16:15 CET
Nmap scan report for ubuntu-wsl2 (172.26.183.209)
Host is up (0.000045s latency).

PORT     STATE SERVICE
8080/tcp open  http-proxy

Nmap done: 1 IP address (1 host up) scanned in 0.02 seconds

WSL2@~» curl http://172.26.183.209:8080 > /dev/null
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

From inside a container, however:

[root@0467b7ef17e7 /]# nmap -Pn -p 8080 172.26.183.209
Starting Nmap 7.70 ( https://nmap.org ) at 2020-12-23 15:12 UTC
Nmap done: 1 IP address (0 hosts up) scanned in 0.43 seconds
[root@0467b7ef17e7 /]# curl http://172.26.183.209:8080
curl: (7) Failed to connect to 172.26.183.209 port 8080: No route to host

It also works from inside the docker-desktop WSL2 container:

WSL2@~» wsl.exe -d docker-desktop wget http://172.26.183.209:8080
Connecting to 172.26.183.209:8080 (172.26.183.209:8080)     
Connecting to host.docker.internal:8180 (192.168.0.202:8180)
index.html           100% |********************************|  7308  0:00:00 ETA

Just not from inside the containers. Until I reboot. AAAARRRRRHHHHHHHHHHHHHHHH :-)

One hint - something that doesn't make sense to me - is this from inside a container:

[root@0467b7ef17e7 /]# ping 172.26.183.209
PING 172.26.183.209 (172.26.183.209) 56(84) bytes of data.
From 172.26.0.2 icmp_seq=1 Destination Host Unreachable
From 172.26.0.2 icmp_seq=2 Destination Host Unreachable
From 172.26.0.2 icmp_seq=3 Destination Host Unreachable
^C
--- 172.26.183.209 ping statistics ---
6 packets transmitted, 0 received, +3 errors, 100% packet loss, time 202ms
pipe 4

What is 172.26.0.2? Hmm...

Networking setup:

(I've modified Ethernet 3's IP address since it's in the corporate network)

WSL2@~» ip -br a
lo               UNKNOWN        127.0.0.1/8 ::1/128 
bond0            DOWN           
dummy0           DOWN           
sit0@NONE        DOWN           
eth0             UP             172.26.183.209/20 fe80::215:5dff:fef9:cc5c/64 
WSL2@~» ipconfig.exe

Windows IP Configuration


Ethernet adapter Ethernet 3:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::405f:b7d2:70b4:b405%19
   IPv4 Address. . . . . . . . . . . : 10.14.11.17
   Subnet Mask . . . . . . . . . . . : 255.255.255.255
   Default Gateway . . . . . . . . . : 10.14.11.18

Ethernet adapter Ethernet 4:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Ethernet:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::7cd1:5641:ac65:7004%15
   IPv4 Address. . . . . . . . . . . : 192.168.0.202
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.0.1

Ethernet adapter VirtualBox Host-Only Network:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::f06d:9785:cff5:2ad0%6
   IPv4 Address. . . . . . . . . . . : 192.168.225.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Wireless LAN adapter Wi-Fi:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 7:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 10:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Ethernet 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::c507:3c2b:62d:7270%39
   IPv4 Address. . . . . . . . . . . : 172.26.176.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

WSL2@~» route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.26.176.1    0.0.0.0         UG    0      0        0 eth0
172.26.176.0    0.0.0.0         255.255.240.0   U     0      0        0 eth0
Waxy answered 23/12, 2020 at 15:37 Comment(5)
Have you found a solution to that problem?Obadias
I still have intermittent network problems using Docker, WSL2 and Windows. I'm not sure I've seen this particular problem again, and hence don't have a fix.Textile
I have the same issue. Network calls via docker container are running into timeouts. Have you found a solution to this issue?Unwell
I have since left that company and am now (thankfully) back to using Linux only, so I'm not able to provide more info on this.Textile
this worked for me #72531067Concurrence
U
20

I had a similar issue where the IP address for WSL2 conflicted with the 172.17.0.0/16 address space which Docker uses internally. In my case, in WSL2:

$ hostname -I
172.17.112.35

The fix was to change the address space Docker uses to a different one which also doesn't conflict with my local network. In the settings in Docker Desktop, set "bip": "192.168.200.1/24" on the Docker Engine configuration page.

Credit: https://www.beyondjava.net/docker-wsl-network

enter image description here

Restarting your PC or WSL "fixes" this issue temporarily because the IP assigned to WSL happens to not conflict with addresses used by Docker.

Unsightly answered 9/8, 2022 at 6:27 Comment(4)
This should be the pinned answer. IT states the fundamental conflict and permanent solution.Goodrich
The symptoms of this for me were subtle. Networking would work for a short while after starting dockerd, but eventually my entire WSL system would not lose internet connectivity. This solution worked.Deepsea
You're the first to have a real solution to this never ending problem. Thank you!Gigue
There is a bug on the desktop interface, it doesn't accept /24 CIDR due formatting error. Editing user/.docker/deamon.json did the trick.Dalpe
A
0

Have you tried just restarting the container and not the whole machine? It sounds like it's the container losing track of its network configuration. A lot of things with containers are written at startup and never updated or not consistently updated.

Artist answered 4/2, 2021 at 21:58 Comment(1)
I don't remember. It only happens once in a while. I'm pretty sure, but not certain, that I would've tried that. I'm also pretty sure, but not certain, that I would've tried to confirm that the symptoms were present in multiple containers. I'll keep that in mind next time it happens...Textile
L
0

I'm still looking for a solution, but I found a quicker workaround: just restart WSL2. From a cmd window, enter:

wsl --shutdown

Docker will complain about having stopped unexpectedly, and then will give you another message when you restart it, but that's not harmful.

Landwehr answered 26/1, 2022 at 18:16 Comment(0)
E
0

I faced this problem recently while trying to use Xdebug with Docker and WSL2. I tried everything from changing VSCode/Xdebug settings, disabling firewalls, and various internet/network troubleshooting steps, but nothing seemed to help or suggest any reason why my Docker container couldn't access my WSL2 host IP.

Finally, in desperation I uninstalled Docker and reinstalled it and Xdebug magically works again! So if all else fails, try reinstalling Docker Desktop.

Epiphytotic answered 5/11, 2023 at 19:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.