WSL 2.0: `networkingMode=mirrored` makes Docker unable to forward ports
Windows Version
Microsoft Windows [Version 10.0.22631.2338]
WSL Version
2.0.0.0
Are you using WSL 1 or WSL 2?
- [X] WSL 2
Kernel Version
5.15.123.1-1
Distro Version
Ubuntu 20.04.6
Other Software
Docker version 24.0.6, build ed223bc
Repro Steps
- Change
networkingModetomirrored docker run -d -p 8080:80 nginx:alpine(example)- Go to
localhost:8080 - Cannot connect
- Try from WSL
curl http//localhost:8080same issue
Expected Behavior
To forward the port and be able to connect to my containers
Actual Behavior
Doesn't forward the port, so I cannot connect to my containers.
Diagnostic Logs
No response
Interestingly, the port forwarding does work from another machine on the same network as host. Just not on the host machine itself.
Machine A:
- Change networkingMode to mirrored
- docker run -d -p 8080:80 nginx:alpine
- Go to localhost:8080
- Cannot connect
- Set Windows firewall rules to allow 8080 inbound
- Go to localhost:8080
- Cannot connect
Machine B:
- Go to A:8080
- works
Same issue
Maybe related issues: https://github.com/docker/for-win/issues/13686
Same problem here
Yup, it's unfortunate but I have the same issue. I am on the release channel with windows version 10.0.22621.2359
Same problem here
~~In my case, Docker ports are not exposed to the host Windows machine at all after the upgrade to 2.0 even if I set networkingMode=NAT which is the default value. I can't see opened ports in the tcpview.exe utility. Previously, I was able to see them opened by the wslhost.exe process (or similar name).~~
Switching to NAT helped me.
same here
+1
+1
+1
@benhillis Any ideas/updates here?
same here
+1
Same issue here, the only way I found to make it "work" was adding ignoredPorts=8080 to the wslconfig, but if container has something like 4800:8080 need to add both ports to ignoredPorts=8080,4800 still doing this some containers might not work at all, also if cloudflare tunnel is running on WSL this will break to when mirrored and theres no way to know which ports is using to add it to the ignoredPorts
Same issue here, the only way I found to make it "work" was adding ignoredPorts=8080 to the wslconfig, but if container has something like 4800:8080 need to add both ports to
ignoredPorts=8080,4800still doing this some containers might not work at all, also if cloudflare tunnel is running on WSL this will break to when mirrored and theres no way to know which ports is using to add it to theignoredPorts
I think that's a workaround that would work... but I am waiting for someone from the WSL team to answer us here, did they get to know that is the issue, and if they have any plans to fix this?
Same issue here, the only way I found to make it "work" was adding ignoredPorts=8080 to the wslconfig, but if container has something like 4800:8080 need to add both ports to
ignoredPorts=8080,4800still doing this some containers might not work at all, also if cloudflare tunnel is running on WSL this will break to when mirrored and theres no way to know which ports is using to add it to theignoredPorts
That seems to work. Nice find.
ignorePorts is misleading. What it does is making in this case port 8080 available to request inside the container only, but is not forwarded to Windows side. Look for more details at https://learn.microsoft.com/en-us/windows/wsl/wsl-config
If you run get-nettcpConnection -LocalPort 8080 there's nothing listening on that port.
After starting the web server with docker run -d -p 8080:80 nginx:alpine requests inside the WSL container works:
zcobol@debian:~$ curl -I localhost:8080
HTTP/1.1 200 OK
Server: nginx/1.25.2
Date: Mon, 25 Sep 2023 16:41:36 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 15 Aug 2023 19:24:07 GMT
Connection: keep-alive
ETag: "64dbd0d7-267"
Accept-Ranges: bytes
Requests from Windows side timeout with:
curl: (28) Failed to connect to localhost port 8080 after 21276 ms: Couldn't connect to server
From another server it work, as mentioned by @driver1998 :
tux@raspi:~$ curl -I 192.168.1.105:8080
HTTP/1.1 200 OK
Server: nginx/1.25.2
Date: Mon, 25 Sep 2023 16:43:45 GMT
Content-Type: text/html
Content-Length: 615
Last-Modified: Tue, 15 Aug 2023 19:24:07 GMT
Connection: keep-alive
ETag: "64dbd0d7-267"
Accept-Ranges: bytes
Just ran into this as well. AWS sam build --use-container doesn't work. Gives the same error
Ports are not available: exposing port TCP 127.0.0.1:5232 -> 0.0.0.0:0: listen tcp 127.0.0.1:5232: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
(The port number changes randomly every time)
Based on this: https://github.com/aws/aws-sam-cli/blob/c5b9b1e399a1e5c938ef72934a14ede934e17bac/samcli/local/docker/container.py#L124-L125
I added every port from 5000-9000 to the ignoredPorts list. It's ugly, but for now it works.
Just ran into this as well. AWS
sam build --use-containerdoesn't work. Gives the same errorPorts are not available: exposing port TCP 127.0.0.1:5232 -> 0.0.0.0:0: listen tcp 127.0.0.1:5232: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.(The port number changes randomly every time)
Based on this: https://github.com/aws/aws-sam-cli/blob/c5b9b1e399a1e5c938ef72934a14ede934e17bac/samcli/local/docker/container.py#L124-L125 I added every port from 5000-9000 to the
ignoredPortslist. It's ugly, but for now it works.
It seems like it's generally a problem with WSL itself. I am looking for a fix soon, since the new network mode is so much useful but it's not useable (usefully) in the current state.
I ma having the same issue with apache. No changes other than added --experimental but now nothing works.
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down [no listening sockets available, shutting down](apache2.service: Control process exited, code=exited, status=1/FAILURE)
root@ACER-Nitro:/usr/sbin# lsof -nP -iTCP -sTCP:LISTEN COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME systemd-r 308 systemd-resolve 14u IPv4 22507 0t0 TCP 127.0.0.53:53 (LISTEN) mysqld 385 mysql 21u IPv4 32886 0t0 TCP 127.0.0.1:33060 (LISTEN) mysqld 385 mysql 23u IPv4 27396 0t0 TCP 127.0.0.1:3306 (LISTEN) miniserv. 1867 root 5u IPv4 52863 0t0 TCP *:10000 (LISTEN)