Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
PaulBurridge opened this issue Mar 9, 2023 · 11 comments

Comments

@PaulBurridge
Copy link

PaulBurridge commented Mar 9, 2023

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 #9751 (comment)

@PaulBurridge
Copy link
Author

Original request to raise this as a new issue:
#9751 (comment)

VSCode Issue:
microsoft/vscode-remote-release#8154 (comment)

Scenario:

  • Working in a container running in Docker service installed on WSL with no ports forwarded to the WSL OS.
  • Connected to container using VSCode remote containers.
  • Open a web application service on port 5000 (note any port has same behavior), this is accessible to requests within the container.
  • This port is not listening on the WSL OS and thus is not accessible to requests from the WSL OS.
  • wslhost.exe incorrectly attempts to tunnel port from the WSL OS to Windows and creates a listener on Windows port 5000. This port does not function as there is no listener on the WSL OS.
  • VSCode tries to do its own tunneling of the port from within the Docker container to Windows which fails due to the existence of a listener created by wslhost.exe so instead tunnels to another port (original port+1)
  • After a while the listener opened on Windows port 5000 by wslhost.exe closes.

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

@ghost
Copy link

ghost commented Mar 9, 2023

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Author

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
Copy link

ghost commented Mar 13, 2023

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
Copy link

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
Copy link

jacobshilitz commented Jul 17, 2023

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
Copy link
Author

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
Copy link

gund commented Nov 7, 2023

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.

Copy link
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants