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

WSL2 can't reach a docker container's ports mapped to 127.0.0.1 #9515

Closed
1 of 2 tasks
fabis94 opened this issue Jan 20, 2023 · 9 comments
Closed
1 of 2 tasks

WSL2 can't reach a docker container's ports mapped to 127.0.0.1 #9515

fabis94 opened this issue Jan 20, 2023 · 9 comments

Comments

@fabis94
Copy link

fabis94 commented Jan 20, 2023

Version

Windows version: 10.0.22621.1192

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.15.83.1

Distro Version

Ubuntu 20.04

Other Software

DOCKER:
Client:
Cloud integration: v1.0.29
Version: 20.10.22
API version: 1.41
Go version: go1.18.9
Git commit: 3a2c30b
Built: Thu Dec 15 22:36:18 2022
OS/Arch: windows/amd64
Context: default
Experimental: true

Server: Docker Desktop 4.16.2 (95914)
Engine:
Version: 20.10.22
API version: 1.41 (minimum version 1.12)
Go version: go1.18.9
Git commit: 42c8b31
Built: Thu Dec 15 22:26:14 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.14
GitCommit: 9ba4b250366a5ddde94bb7c9d1def331423aa323
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0

VSCode: 1.74.3 w/ Remote WSL extension

Repro Steps

Not sure if this is reproducible, since the issue just appeared out of nowhere - things worked fine yesterday

Expected Behavior

WSL2 should be able to connect to any containers with port mappings that explicitly use 127.0.0.1 as the hostname instead of the very permissive 0.0.0.0.

Actual Behavior

For some reason docker containers started with port mappings that map to 127.0.0.1 specifically, e.g. -p 127.0.0.1:8020:8020 don't work inside the WSL2 (Ubuntu) environment. I've got a basic web server container started this way and any attempts to curl http://127.0.0.1:8020 from inside the WSL2 environment (not even from Windows!) fail with a "Connection refused".

It's as if the Docker container is blocking the connection because it thinks the connection that is coming from 127.0.0.1 actually isn't coming from 127.0.0.1, because if I just use a port mapping like -p 8020:8020 which maps the ports to 0.0.0.0 instead of 127.0.0.1 then it works and the connection to the web server isn't refused anymore.

I tried debugging this by making my web server respond by emitting the incoming request IP into the body and saw something strange. I ran the web server with -p 8020:8020 to make sure I can connect to it, did a curl http://127.0.0.1:8020 from inside WSL2 (not Windows!) and the remote address was outputted to be: 172.17.0.1.

Could that be the issue? The remote address should be 127.0.0.1, but it comes in as 172.17.0.1 so Docker doesn't allow connections from WSL2 if the ports are explicitly only mapped to 127.0.0.1

image

image

Diagnostic Logs

WslLogs-2023-01-20_16-40-07.zip

@jmar5439
Copy link

It happens to me, again after last update 22623.1180
I turned off "Fast Startup" and it seems to work

@fabis94
Copy link
Author

fabis94 commented Jan 20, 2023

It happens to me, again after last update 22623.1180 I turned off "Fast Startup" and it seems to work

Didn't work for me unfortunately, but thanks for the comment

@jmar5439
Copy link

it worked just for only one page load
After that continued to fail ;(

@fedotov2d
Copy link

fedotov2d commented Jan 23, 2023

Highly likely related to recent similar issues: WSL/issues/9516 and WSL/issues/9508

@fabis94
Copy link
Author

fabis94 commented Jan 23, 2023

For what it's worth, a full clean windows (re)install seems to have helped

@mickdewald
Copy link

mickdewald commented Jan 23, 2023

For what it's worth, a full clean windows (re)install seems to have helped

That is overkill and unnecessary. This seems to be a bug, so just revert to an older WSL version for the time being like here:
#9516 (comment)

@fabis94
Copy link
Author

fabis94 commented Jan 23, 2023

For what it's worth, a full clean windows (re)install seems to have helped

That is overkill and unnecessary. This seems to be a bug, so just revert to an older WSL version for the time being like here: #9516 (comment)

I didn't bother doing that because I hadn't upgraded wsl once that started happening, but I'm glad it worked for you

@ghost ghost self-assigned this Jan 23, 2023
@ghost
Copy link

ghost commented Jan 23, 2023

Non deterministic repro instructions here: #9516 (comment) . If someone is experiencing failure to forward after a period other than exactly 1 minute then please say. Because in that case there may be a second issue. Thanks again for your patience.

/dupe #9508

@ghost ghost closed this as completed Jan 23, 2023
@ghost
Copy link

ghost commented Jan 23, 2023

Hi! We've identified this issue as a duplicate of another one that already exists in this repository. This specific instance is being closed in favor of tracking the concern over on the referenced thread.

Thanks for your report!

This issue was closed.
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

4 participants