The second container in this list provides a web based user-interface, accessed by going to a web browser and going to localhost:4443. If I just run this program in WSl2 and not in a container, it works fine. I need to run it in a container though. No matter what I have tried, I get that the site cant be reached.
These containers were built with a docker compose file.
In the compose file I set for the container I am interested in:
I had installed docker desktop at one point that caused a ton of problems after having used the linux version first in WSL2. I thought perhaps completely reinstalling everything would help so I completely removed Wsl2 and Ubuntu. Got the same issue with a clean install.
Using the ip address instead of localhost. Tried connecting to 172.30.240.77:4443 and had no luck. Tried 127.0.0.1 and also had no luck.
Note
I must note that it randomly worked a SINGLE time. Not sure what I did, but it stopped working and has not worked since.
I installed the docker engine via command line in WSL2. Then I installed windows docker desktop. I did not initially want docker desktop but needed it later on. I removed everything though and started from scratch without docker desktop in windows.
If you run docker inside the WSL2 (regardless whether it is Docker Desktop for Linux or docker-ce), every port you publish, will be published inside the WSL2 distribution. If you bind a port in a WSL2 distribution, it will be mapped to the same port on Windows hosts localhost interface. The port will not be bound to any other host interface or ip.
If you need the containers to be reachable from the host-ip (e.g. from other hosts in your lan), you will need to manually configure portforwarding. Google should yield plenty of blog posts that explain how to forward traffic from the host ip to WSL2 distributions.
I run docker-ce in a wsl2 distro, and I can reach published container ports in Windows using localhost:{host port}.
If this doesn’t work, you might want to check if a firewall or a vpn connection is responsible that the communication the host and the wsl distribution is not working.
Thank you for your response. The first thing I tried above was to manually forward the ports, I have included the configuration above. Isn’t that what you are talking about?
The take away should have been, that if you run a self installed docker engine inside a WSL distribution, then publishing a port like this:
Should be reachable on the Windows host from localhost:5443, without having to configure anything.
Your problem is caused by how WSL2 works. The docker engine installed inside the WSL2 distribution is neither part of the problem, nor part of the solution.
Thanks but your last sentence has left me confused. You state that what I should have taken away was that what I did should be working but then say its caused by how WSL2 works. Looks like its likely a firewall issue of some sort, correct?
Also, like I said, I can access the WSL2 instance application when running the application without docker. It is only when I run the container that I have this issue.
Try it yourself:
Start a nginx container in your wsl distro with port 80 published:
sudo docker run --rm -ti -p 80:80 nginx
Then you should be able to access it from the Windows host in a browser with http://localhost, or from the terminal with curl http://localhost
if the host port is already bound by another port use -p {whatever port}:80 when starting the container and http://localhost:{whatever port} when opening the url in the browser and querying it with curl.
I had similar problem, but i overcame it by removing all port proxies one after the other. I used this commands: To show all ports proxy: netsh interface portproxy show all To delete each of them: netsh interface portproxy delete v4tov4 listenport=3000 listenaddress=172.17.0.3