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

Cannot access windows server from docker in wsl2 with mirrored network. #12626

Open
1 of 2 tasks
XTxxxx opened this issue Feb 23, 2025 · 4 comments
Open
1 of 2 tasks

Cannot access windows server from docker in wsl2 with mirrored network. #12626

XTxxxx opened this issue Feb 23, 2025 · 4 comments

Comments

@XTxxxx
Copy link

XTxxxx commented Feb 23, 2025

Windows Version

Microsoft Windows [version 10.0.22631.4317]

WSL Version

2.4.11.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.167.4-1

Distro Version

Ubuntu24.04

Other Software

Docker (not docker desktop)

Docker version 28.0.0, build f9ced58

Repro Steps

When I first encountered this issue while deploying a local service using Docker Compose, the working environment was quite complex. With the help of AI, I simplified the scenario and successfully reproduced the problem.

  1. First, set up port 7890(a http proxy) to listen on the Windows host machine and ensured that its binding address was configured to 0.0.0.0
    Image
    And I'm sure I can access the proxy on wsl.
    Image
  2. Second, create docker-compose.yml and enter the container.
version: "3.8"

services:
  test:
    image: alpine:latest
    entrypoint: ["sh", "-c", "tail -f /dev/null"]  
    extra_hosts:
      - "host.docker.internal:host-gateway" 
  1. Then enter the shell and test
docker compose up -d
docker compose exec test sh
apk add --no-cache curl
curl -x http://host.docker.internal:7890 https://google.com -v

Expected Behavior

I expect that the curl command will successfully connect to the proxy and work properly.

Actual Behavior

/ # curl -x http://host.docker.internal:7890 https://google.com -v
* Host host.docker.internal:7890 was resolved.
* IPv6: (none)
* IPv4: 172.18.0.1
*   Trying 172.18.0.1:7890...
* connect to 172.18.0.1 port 7890 from 172.18.0.1 port 44111 failed: Connection refused
* Failed to connect to host.docker.internal port 7890 after 0 ms: Could not connect to server
* closing connection #0
curl: (7) Failed to connect to host.docker.internal port 7890 after 0 ms: Could not connect to server

Diagnostic Logs

WslNetworkingLogs-2025-02-24_02-41-55.zip

Copy link

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'.
Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How 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 script will output the path of the log file once done.

If this is a networking issue, please use collect-networking-logs.ps1, following the instructions here

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

Click here for more info on logging
If you choose to email these logs instead of attaching to the bug, please send them to [email protected] with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

@XTxxxx
Copy link
Author

XTxxxx commented Feb 23, 2025

/question

Copy link

Diagnostic information
Found '/question', adding tag 'question'

@XTxxxx
Copy link
Author

XTxxxx commented Feb 23, 2025

Additional: If I replace host.docker.internal with the host machine's IP address (displayed by running ipconfig.exe in PowerShell), I can successfully connect to the proxy server. But why can't localhost or host.docker.internal work here?

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

No branches or pull requests

2 participants