You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[WSL 2] can't access container in WSL from Windows #4170
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
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.
Reacted by Craig Loewen, markmail, Jacob Hamblin, marioeu, jeshio, ramondejonge, Mehdi Hadeli and Mustafa Korkmaz
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
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...
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?
Reacted by Krzysztof Marczak and Gabriel Henrique da Silva Ferreira
Activity
brdhunga commentedon Jun 17, 2019
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 commentedon Jun 17, 2019
It will change with every new session but you can read the IP easily from task manager:
markmail commentedon Jun 18, 2019
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 commentedon 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 commentedon Sep 9, 2020
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?