I run into an issue with a docker and WSL2 configuration that was running ok for weeks…
I’m running a docker Apache2 web server on Ubuntu WSL2 with port forwarding.
I can see using nmap the 8080 Ubuntu port is open when docker image is running.
I can curl the web server from within the Ubuntu WSL2 using both 127.0.0.1:8080 and eth0 inet address (172.17.118.136:8080) and get the apache default page.
I have an issue when trying to access the web server from my Windows host with the Ubuntu eth0 inet address : connection timed out.
From my Windows host the ping of Ubuntu eth0 is ok, and when I run an Apache2 web server directly from Ubuntu WSL2 (no docker), my Windows host is able to connect to it using eth0 inet address.
2
Answers
I solved the issue thanks to jishi comment on this thread : https://github.com/microsoft/WSL/issues/4983#issuecomment-602487077
Using the ipv6 localhost url [::1] worked for me.
You can use the following lsof command in WSL2 to find out on which port the docker is running and then use that port to connect:
You will get a result like this:
The port for me is 49157:
so, I can access the Docker container which is inside WSL through Windows by
http://localhost:49157
or by wsl inet ip ->http://172.31.255.167:49157
Note: if lsof is not installed then use the following command to install it: