No Browser Access - Contenerazied Web App - WSL2 Windows11 - No Docker Desktop Used

Hi,

I am having an issue for getting access to contenarized web apps (React) from my web browser in Windows running in WSL2 without using docker desktop.

I don’t know what could be the problem. I did a bare installation of docker following this post.

If I run my React app normally (without container), I don’t have any issues with Windows and WSL2 (just put localhost:3000 in Chrome and I have access to my app). My default port forwarding dows the work and I am able to access my app from my browser. However, if I do the runn the same app in a container, I am not able to access it with a web browser. Weirdly, if I do a curl command to the containerized app inside WSL2 (curl http://localhost:3000), I get a response with the initial HTML of the. What could be the problem? I still can’t find the issue.

Below I show an example with you some outputs I got doing a test running an Apache Server mapped to port 80 in my localhost.

Details about my running containers (Zsh Shell - Ubuntu - WSL2)

➜  ~ docker ps -a
CONTAINER ID   IMAGE     COMMAND              CREATED         STATUS         PORTS                               NAMES

86e9b3e69415   httpd     "httpd-foreground"   3 minutes ago   Up 3 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp   apache

Details from running curl in my Ubuntu distribution inside WSL (Zsh Shell - Ubuntu - WSL2)

➜  ~ curl localhost:80
<html><body><h1>It works!</h1></body></html>

Details about my WSL version (Powershell Windows)

PS C:\Users\samuelv> wsl --version
WSL version: 2.2.4.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.61
MSRDC version: 1.2.5326
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26091.1-240325-1447.ge-release
Windows version: 10.0.22621.3737

Details about my Linux Distribution (Zsh Shell - Ubuntu - WSL2)

➜  ~ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy

For the example given above, if I try in this case to get to localhost in my browser (localhost:80 or localhost, both the same), I can’t get access. But with the curl command inside WSL2, I don’t have any issues. What could be the problem?

WSL2 allows accessing ports bound in the WSL2 distribution from the Windows host, without any extra effort, regardless whether you run the process directly inside WSL2 distribution, or as a docker container with published ports.

Though, you can not access it by using the host ip and port, as this requires extra port forwarding rules in the Windows Firewall.

This is default WSL2 behavior.

Note: Docker Desktop takes of port forwarding to make a container reachable on the host ip and published port. Not relevant for your situation, but I thought I mention it.

1 Like

I have the same issue under wsl -Debian, even when Windows Defender firewall if completely off. In addition, I tried to disable IPv6 in /etc/sysctl.conf, but still no access from Windows 11 browser to http://localhost:8888

PS C:\WINDOWS\system32> netsh interface portproxy show all

Listen on ipv4:             Connect to ipv4:

Address         Port        Address         Port
--------------- ----------  --------------- ----------
127.0.0.1       80          172.30.128.1    80
127.0.0.1       8080        172.30.128.1    8080
127.0.0.1       8888        172.30.128.1    8888
0.0.0.0         8888        172.30.128.1    8888
0.0.0.0         8080        172.30.128.1    8080

PS C:\WINDOWS\system32>

I also tried to change /etc/ws.conf:

[boot]
systemd=true
[network]
generateResolvConf = false
namesever 0.0.0.0

and ~/.wsconfig:

[wsl2]
localhostForwarding=true
networkingMode=mirrored
hostAddressLoopback=true
debugConsole=true
autoProxy=true

Do I need to enable firewall and set rules for port forwarding?