microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.44k stars 822 forks source link

WSL attempting to expose a port that is only open within a Docker container #9763

Closed PaulBurridge closed 3 days ago

PaulBurridge commented 1 year ago

Evidence below of WSL attempting to expose a port that is only open within a Docker container

Docker service is installed inside WSL OS (tested with Ubuntu and Debian)

Note no port exposed to WSL OS in docker command

Steps to reproduce:

>wsl --shutdown

>netstat -ano | find "LISTENING" | find ":80"

>wsl -e echo "WSL started"
WSL started

>netstat -ano | find "LISTENING" | find ":80"

>wsl -e docker run -d nginx
ea266215b1c431023655824e8a980fe2161e3c55700a03466f924c4ba11e82f2

>netstat -ano | find "LISTENING" | find ":80"
  TCP    127.0.0.1:80           0.0.0.0:0              LISTENING       19820
  TCP    [::1]:80               [::]:0                 LISTENING       19820

>tasklist /fi "PID eq 19820"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
wslhost.exe                  19820 Console                    3      7,500 K

>curl http://localhost:80
curl: (7) Failed to connect to localhost port 80 after 2239 ms: Connection refused

>wsl -e curl http://localhost:80
curl: (7) Failed to connect to localhost port 80: Connection refused

# A short while later the port dissapears

>netstat -ano | find "LISTENING" | find ":80 "                                                                                

>wsl --version
WSL version: 1.1.3.0
Kernel version: 5.15.90.1
WSLg version: 1.0.49
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22000.1574

Originally posted by @PaulBurridge-Nasstar in https://github.com/microsoft/WSL/issues/9751#issuecomment-1460267767

PaulBurridge commented 1 year ago

Original request to raise this as a new issue: https://github.com/microsoft/WSL/issues/9751#issuecomment-1460661786

VSCode Issue: https://github.com/microsoft/vscode-remote-release/issues/8154#issuecomment-1459889181

Scenario:

VSCode is not required to demonstrate this issues see my first post of the simplest recreation of the issue.

ghost commented 1 year ago

Please provide /logs

  1. wsl --shutdown
  2. Start log collection
  3. Reproduce the issue and confirm that it is broken
  4. Stop the log collection.

Thank-you

microsoft-github-policy-service[bot] commented 1 year ago

Hello! Could you please provide more logs to help us better diagnose your issue?

To collect WSL logs, download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The scipt will output the path of the log file once done.

Once completed please upload the output files to this Github issue.

Click here for more info on logging

Thank you!

microsoft-github-policy-service[bot] commented 1 year ago

Hello! Could you please provide more logs to help us better diagnose your issue?

To collect WSL logs, download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The scipt will output the path of the log file once done.

Once completed please upload the output files to this Github issue.

Click here for more info on logging

Thank you!

PaulBurridge commented 1 year ago

The powershell version did not work for me so I submitted using windows feedback system as detailed in link above, hopefully you can access from there.

ghost commented 1 year ago

Sometimes those work, sometimes they don't. Thanks for letting me know it's in feedback hub.

I'm sorry, I got rerouted elsewhere last week and won't be able to jump on this for the time being. When I do, I'll look.

soda0289 commented 1 year ago

Version 1.1.5 of wsl seems to not have the issue with docker ports being exposed to windows. After upgrading to version 1.1.6 I had the same issue with docker of port already in use. My docker container binds to port 80 on 0.0.0.0 but would return port in use since windows is already listening on port 80.

jacobshilitz commented 1 year ago
C:\Users\jacob>wsl --version
WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.1105

by me, it was running Apache on port 80, and it turns out that this was due to running WSL ubuntu in systemd mode, and I solved it by removing systemd=truefrom /etc/wsl.conf and restarted WSL.

PaulBurridge commented 1 year ago
C:\Users\jacob>wsl --version
WSL version: 1.2.5.0
Kernel version: 5.15.90.1
WSLg version: 1.0.51
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.1105

by me, it was running Apache on port 80, and it turns out that this was due to running WSL ubuntu in systemd mode, and I solved it by removing systemd=truefrom /etc/wsl.conf and restarted WSL.

Good to know, unfortunately I need systemd

gund commented 1 year ago

FYI for me this issue only occurs when I set experimental.networkingMode=mirrored in my .wslconfig file. If I comment it out then it's not messing with ports and also vscode does not increase forwarded ports by 1. Note, I use mirrored networking mode when I need to SSH into an IPv6-only servers, otherwise IPv6 stack is not available in WSL.

microsoft-github-policy-service[bot] commented 3 days ago

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!