MicrosoftDocs / WSL

Source code behind the Windows Subsystem for Linux documentation.
https://docs.microsoft.com/windows/wsl
Other
1.92k stars 579 forks source link

Accessing a WSL 2 distribution from your local area network (LAN) not working #2061

Open Olcod opened 5 days ago

Olcod commented 5 days ago

Type of issue

Code doesn't work

Feedback

Using Ubuntu-24-04 WSL2 distro:

PS C:\WINDOWS\system32> wsl -l -v                                                                                                                                                            NAME                   STATE           VERSION                                                                                                                                           * Ubuntu-24.04           Stopped         2                                                                                                                                                   docker-desktop-data    Running         2                                                                                                                                                   docker-desktop         Running         2

I ran the netsh command to add windows port mapping:

PS C:\WINDOWS\system32> netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=8080 connectaddress=172.17.145.122 

The WSL IP is correct:

PS C:\WINDOWS\system32> wsl hostname -I                                                                                                                                                    172.17.145.122

When I try to run Gatus container running, on the WSL distro docker run -p 8080:8080 --name gatus twinproduction/gatus, this is what I get:

~$ docker run -p 8080:8080 --name inline-gatus twinproduction/gatus
docker: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:8080 -> 0.0.0.0:0: listen tcp4 0.0.0.0:8080: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.

Removing the netsh interface portproxy fixes docker error, but then I cannot access the container on host's private IP. Without the portproxy, I can access the container on localhost:8080 and on 172.17.145.122:8080, host's private IP requests time out.

Page URL

https://learn.microsoft.com/en-us/windows/wsl/networking

Content source URL

https://github.com/MicrosoftDocs/wsl/blob/main/WSL/networking.md

Author

@mattwojo

Document Id

f9e21bfa-6316-7d45-3b34-834a78bcaf0f