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 2] can't access container in WSL from Windows #4170

Closed
markmail opened this issue Jun 17, 2019 · 5 comments
Closed

[WSL 2] can't access container in WSL from Windows #4170

markmail opened this issue Jun 17, 2019 · 5 comments
Labels

Comments

@markmail
Copy link

Unable to access localhost from Windows

start container in WSL with

docker run -p 9001:8080 adminer

curl http://localhost:9001 returned with result no problem

however when I performed the same curl command from Windows land, the connection was refused

curl: (7) Failed to connect to localhost port 9001: Connection refused

check with netstat under Windows, and confirmed port 9001 is not visible from Windows

Microsoft Windows [Version 10.0.18917.1000]
Ubuntu 18.04.2 LTS
Docker version 18.09.6, build 481bc77

Ubuntu installed from Microsoft Store and converted to WSL 2 as per official Microsoft instruction
Docker installed as per official Docker guide for Ubuntu

@brdhunga
Copy link

You have to use the ip address of WSL 2 (as it is a hyper-v container). you can do so by running ip addr | grep eth0 within WSL 2 terminal, and you can use that ip address to access any port. You might have to play with the firewall too.

@onomatopellan
Copy link

onomatopellan commented Jun 17, 2019

It will change with every new session but you can read the IP easily from task manager:

Anotación 2019-06-18 003949

@markmail
Copy link
Author

Isn't that obvious, haha.

Thanks for pointing that out, solved my problem big time. I keep recalling someone from one of the WSL 2 presentation I watched saying that WSL 2 networking environment is the same as native Windows environment....etc perhaps he was referring to future release

@marioeu
Copy link

marioeu commented May 9, 2020

Its worth to say that with WSL (version 1) localhost/127.0.0.1 works fine. But once updated to WSL 2, its really necessary to run with local eth0 IP address.
And I agree with @markmail... it isnt that obvious and must be highlighted somewhere...

@Antony-Wish
Copy link

The solution works for me.
However, if I run a server in WSL2 instead of in docker container, I can access my service using 127.0.0.1.
Why 127.0.0.1 can be used to access services that run in WSL2 and eth0 should be used to access service in docker container?

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

No branches or pull requests

6 participants