-
Notifications
You must be signed in to change notification settings - Fork 845
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
Can't connect to docker container running inside WSL2 #4983
Comments
I had the same problem, and it turned out that WSL2 only binds to ipv6 localhost ([::1]) and not ipv4 localhost (127.0.0.1). It took me a while to figure out, because some applications default to ipv6 resolve first, and other apps (like node.js) defaults to ipv4 lookup. Hence, the host I resorted to using the ipv6 localhost url, When you test in WSL2 and connect to localhost with -4 flag, it works because from the WSL side of things it is acessible both via ipv4 and ipv6. From my experience, even if it lists only ipv6 listings in netstat, it does still listen on ipv4, but maybe this is actually the problem, the Windows bridge only forward traffic for the netstat listing and errorneously only binds ipv6 from the host into the WSL subsystem. I hope this helps. |
As doing a search on a similar issue brought me here The workaround [::1] works for ipv6-enabled app, but if you need ipv4, an option is to use the WSL2 subsystem ip adress instead, i.e. the adress returned by doing a
Still quite inconvenient as I think this address changes at every restart of WSL. |
Oh sure. My workaround is only for non-ipv6 enabled apps. |
Ah, that makes sense |
It worked for me @jishi thanks! |
I have tried ip address of both "ip from ifconfig inside wsl" and "http://[::1]:port" and neither worked for "Ubuntu-20.04" on Windows 10 via Wsl2 |
thank you this was helpful..... |
Has anybody make this work on Ubuntu-20.04? |
Same issue as well for me on Ubuntu-20.04 can't connect to docker with any of the suggestions above |
The IPv6 workaround ( |
@massix result example: get the first -> 172.29.51.119 run the command in the shell windows as an administrator (the port, for example, is 3333): listenport is the windows port |
Why cannot I run curl 172.17.16.1:2375 in wsl2 ubuntu with docker desktop for windows? I got 172.17.16.1 IP in this file /etc/resolv.conf on wsl2/ubuntu. I tried to create a interface portproxy like this netsh interface portproxy add v4tov4 listenport=2375 listenaddress=0.0.0.0 connectport=2375 connectaddress=172.17.16.1, but I got error curl: (52) Empty reply from server. if I execute the command docker -H 172.17.16.1:2375 ps, displays this error during connect: Get http://172.17.16.1:2375/v1.24/containers/json: EOF My problem began when I download code and executed on it the fabric8io/docker-maven-plugin. From here, I looked at all forums and google search results, but without success. Is there any idea how could I proceed with this problem? best regards, |
More than one year after and the problem still exist. I used the upload diagnostic tools: 53A83A43-5D21-4978-846F-3FD11662A256/20211206133132 EDIT: |
Me too, this is a serious problem |
I stopped hoping for a fix. As I fear MS will only offer this "premium" feature only over its "freemium" docker desktop :(. |
Same problem.
|
Still having the problem. I was able to make it work on my Ubuntu work laptop, but it's not working on my personal computer. Works on Linux.
Edit: |
This is still happening. |
Explicitly bind the port of the server in the docker container to the port of the WSL2. |
Crimini: |
I wasted 2 days trying with Docker on Windows 11 Pro with WSL. Here is what I did in my case:
One usefull hint. From Powershell you can check proxies and get the address you are looking for. netsh interface portproxy show v4tov4 |
We're using Laravel and this is a MAJOR issue because any work-around screws up all the URL's for links and routing. Is anyone form Microsoft even looking into this? How hard can it be to bind to IPv4 and then IPv6? They hack together WSL so we can even begin to use Docker on THIER OS and then leave us stranded unable to develop and test apps using it. I am trying to convince our CEO to move to mac for dev solely because of this issue, but he is hung up on the $$ difference. Guess it's true though, you do get what you pay for. 3 YEARS LATER AND NOT A PEEP FROM MICROSOFT ON THIS ISSUE. |
this problem still exist on Ubuntu 20.04 |
Hi Yueyi, I also encountered this issue. But I have fixed it through updating the latest version. Maybe you can go to https://github.com/microsoft/WSL/releases and download and install the latest msixhundle file under the Asset attachment. |
oh,thank you, I will have a try. |
Hi, I can connect to my container from another host on my private network by following this https://www.it-connect.fr/wsl-2-port-forwarding-comment-acceder-a-sa-machine-virtuelle-a-distance/ What I have done :
Hope it will help :) |
Cant believe this is still open. What a waste the windows hardware is proving to be for devs |
Just bumped into this problem. Impossible to start my Docker container on Windows:
|
Any updates on this? I've tried the pre-release (1.3.14) to no avail. This complicates using WSL for development with Docker Desktop. |
I had the same problem. (I'm not sure, but I think, that) Solution for me was to check and disable some "unplugged" virtual Network Adapters. Details.
|
@nervousapps re:fix Thank you so much, I knew there had to be a firewall issue, the documentation did not mention the two firewall rules you added. Perhaps this needs updating: https://learn.microsoft.com/en-us/windows/wsl/networking#accessing-a-wsl-2-distribution-from-your-local-area-network-lan The other error in that page is it says to use Note: I found this looking for a solution to how to connect to your Docker Apps over the LAN with WSL. I was connecting from the host just fine, it was specifically over LAN that was my issue until now! Thanks! |
After a whole day of pulling hair out, solved my issue (in my case it was a Vite project) by switching from this:
To this:
Now I can access the project in the browser using http://localhost:5173 as normal. Docker command: docker run -d -p 5173:5173 --name vue-app-container vue-app |
This worked like a charm. Change the app host to bound to |
bind your docker app host to 0.0.0.0, other than 127.0.0.1 works to me. |
this worked for me. why is microsoft so useless in trying to fix such a basic issue? its been 4 years guys. common now. |
Saw the same issue on Windows 10 with wsl Ubuntu-20.04. This doc solved for me. it boils down to the first command of @nervousapps answer |
Much of the networking problems I've encountered with WSL2 and Docker for Windows over the years went away when I switched to Mirrored mode networking.
Then, you can, for instance, access your Windows host from Linux using |
This bug is really annoying! 😠 Common, it's only Windows the only who do this. It should imitate Linux but it doesn't in this way. Anyway, for the folks who are developing on python i suggest the following:
import platform
import detect
if detect.docker and "WSL2" in platform.release():
# Bind to 0.0.0.0 instead of 127.0.0.1 Please @microsoft solve this bug. A lot of people is waiting for you and we don't like to be fooled. |
I am using windows docker desktop v4.33.1. There's a feature in settings > features in development > beta features >enable host networking. It works for me with the feature enabled. |
I know this is super old lol, but this fixed my problem! This seems like port forwarding, but between Windows and the docker container. Which makes sense. I figured it would be something like that but didn't know how to actually do it. |
I'm running a couchbase server inside WSL2 with multiple port-forwarding :
Everything seems to work, I can connect to
localhost:8091
from the Windows Host, I can setup the Couchbase and if I try to connect to the different ports exposed by the container, things look nice and clear:The problem is that if I try to connect to the same ports using a Java server that I'm building, I get a Timeout, 100% of times.
It worked until yesterday if I put the IP address of the WSL VM instead of
localhost
in the configuration file of my server (not the best solution, but at least it worked), then I updated the kernel of the WSL - because I was forced to - and it stopped working.Even after restarting the lxssservice the problem persists.
The only thing that works is if I start the docker container with
--net=host
but then I can't start multiple instances of the same container because of the ports binding..I don't know if it's related but when I run a
netstat
on the WSL machine it seems like only tcp6 bindings have been created but it seems to work if I force a tcp4 connection:If someone has a better solution than the
--net=host
I'm all ears..Thank you everyone in advance, small bugs aside, WSL (and WSL 2 in particular) is what made me get back to Windows as my daily driver.
The text was updated successfully, but these errors were encountered: