Repository navigation
Description
- Your Windows build number: Microsoft Windows [Version 10.0.19041.153]
I'm running a couchbase server inside WSL2 with multiple port-forwarding :
(from Windows) ❯ wsl -l -v
NAME STATE VERSION
* Ubuntu Running 2
(inside WSL) ❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
aaad5f11ad16 couchbase:community "/entrypoint.sh couc…" 17 minutes ago Up 4 minutes 0.0.0.0:8091-8096->8091-8096/tcp, 0.0.0.0:11207->11207/tcp, 0.0.0.0:11210-11211->11210-11211/tcp, 18091-18096/tcp couchbase
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:
(from Windows) ❯ Invoke-RestMethod -Uri http://localhost:8092
couchdb version couchbase
------- ------- ---------
Welcome 6.5.0-4966-community
(from Windows) ❯ Invoke-RestMethod -Uri http://localhost:8093
Invoke-RestMethod: 404 page not found
(from Windows) ❯ Invoke-RestMethod -Uri http://localhost:8094
Invoke-RestMethod: {"error":"Page not found","status":"fail"}
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:
(from WSL) ❯ sudo netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::11207 :::* LISTEN 1510/docker-proxy
tcp6 0 0 :::11210 :::* LISTEN 1496/docker-proxy
tcp6 0 0 :::11211 :::* LISTEN 1481/docker-proxy
tcp6 0 0 :::8091 :::* LISTEN 1593/docker-proxy
tcp6 0 0 :::8092 :::* LISTEN 1579/docker-proxy
tcp6 0 0 :::8093 :::* LISTEN 1566/docker-proxy
tcp6 0 0 :::8094 :::* LISTEN 1552/docker-proxy
tcp6 0 0 :::8095 :::* LISTEN 1538/docker-proxy
tcp6 0 0 :::8096 :::* LISTEN 1524/docker-proxy
(from WSL) ❯ telnet -4 localhost 8091
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
^]
telnet>
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.
Activity
jishi commentedon Mar 23, 2020
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
localhostworks in your browser, but not in, lets say, node.js. I'm thinking Java does the same, since you are experiencing this problem.I resorted to using the ipv6 localhost url,
http://[::1]:8091and it just worked.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.
koying commentedon Jul 21, 2020
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
ifconfiginside wsl.Still quite inconvenient as I think this address changes at every restart of WSL.
icorbrey commentedon Jul 22, 2020
Chris Browet (@koying) The subsystem IP did not work for me, but using the IPv6 loopback address like Jimmy Shimizu (@jishi) recommended works perfectly!
koying commentedon Jul 22, 2020
Oh sure. My workaround is only for non-ipv6 enabled apps.
icorbrey commentedon Jul 22, 2020
Ah, that makes sense
otavionetoca commentedon Aug 12, 2020
It worked for me Jimmy Shimizu (@jishi) thanks!
rvangala936 commentedon Oct 8, 2020
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
BrianLeishman commentedon Oct 8, 2020
If you're using MySQL Workbench, make sure to leave out the brackets and use
::1as the hostcanove commentedon Oct 14, 2020
In my case, MySQL Workbench is the only SQL Viwer app that works with
localhost. Beekeeper Studio was not working, even with WSL IP 172.X.X.X.Using IPV6 localhost

::1works like a charm!angrygorilla commentedon Nov 17, 2020
thank you this was helpful.....
afcruzs commentedon May 16, 2021
Has anybody make this work on Ubuntu-20.04?
tristan-curve commentedon May 21, 2021
Same issue as well for me on Ubuntu-20.04 can't connect to docker with any of the suggestions above
kAlvaro commentedon May 21, 2021
The IPv6 workaround (
::1) works fine for me on Ubuntu 20.04 LTS.beriloqueiroz commentedon May 28, 2021
Massimo Gengarelli (@massix)
run the command on ubuntu:
ip addr | grep -E "\binet.global" | sed -E "s/inet(.)/./\1/"
result example:
172.29.51.119
172.17.0.1
172.18.0.1
get the first -> 172.29.51.119
run the command in the shell windows as an administrator (the port, for example, is 3333):
netsh interface portproxy add v4tov4 listenport=3333 listenaddress=0.0.0.0 connectport=3333 connectaddress=172.29.51.119
listenport is the windows port
listenaddress is the windows address, usually 0.0.0.0
connectport is the ubuntu port
connectaddress is the int ip ubuntu
27 remaining items
jwhipp commentedon Jul 21, 2023
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.
usikpavel commentedon Sep 4, 2023
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.
kanine commentedon Sep 19, 2023
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
wsl hostname -ito get the WSL Host IP but it should saywsl hostname -INote: 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!
themustafaomar commentedon Sep 23, 2023
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:
sarthikg commentedon Sep 24, 2023
This worked like a charm. Change the app host to bound to
0.0.0.0instead of the defaultlocalhostor127.0.0.1.robinloxley1 commentedon Oct 31, 2023
bind your docker app host to 0.0.0.0, other than 127.0.0.1 works to me.
wsl: ubuntu
windows: 11
docker image tested: mlflow
docker run -it --rm -p 5000:5000 ghcr.io/mlflow/mlflow mlflow ui -h 0.0.0.0result: from windows browser, I can access locahost:5000
deadcoder0904 commentedon Feb 15, 2024
this worked for me. why is microsoft so useless in trying to fix such a basic issue?
its been 4 years guys. common now.
General4077 commentedon Feb 15, 2024
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
ismaelhamed commentedon Mar 7, 2024
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
127.0.0.1. Additionally,dnsTunnelingandautoProxycan also help if you're behind a corporate proxy.evilmonkey19 commentedon Apr 24, 2024
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:
detect: https://pypi.org/project/detect/platformPlease Microsoft (@microsoft) solve this bug. A lot of people is waiting for you and we don't like to be fooled.
happyday326 commentedon Aug 29, 2024
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.
Bugsbugme commentedon Sep 11, 2024
I know this is super old lol, but this fixed my problem!
My problem is I have been trying to run a Plex server in a docker container, inside WSL Ubuntu. I wasn't able to enable remote access because my router obviously can only route traffic to my Windows host, but then Windows couldn't route the traffic to the docker container. (at least that's how I see it in my head, I don't know if that's accurate 😅)
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.
craigloewen-msft commentedon May 27, 2025
Hi folks, closing out old issues. I don't think this is reproing anymore, and if you're still seeing this please file it as a new issue. Thank you!
ChristianOConnor commentedon Jul 7, 2025
I created an app with Visual Studio. Everything I did was an out-of-the-box selection. I picked ASP.NET Core Web App (Model-View-Controller) > Framework: .NET 8.0 (Long Term Support), ✔️Enable Container Support, Container OS: Linux, Container build type: Dockerfile` and created the project:
I have Docker Desktop running on Windows 11 with WSL2. It works perfectly on several other docker projects I've tested.
When I try to run the project in Visual Studio by clicking▶️ Container (Dockerfile), it fails to connected with the browser (in this case Edge):
It's extremely vanilla and it won't work out of the box on a 100% up to date Windows/Docker system...
I am pretty sure the error is the ports not being properly routed to the Windows host from WSL2. I tried turning off WSL2 in Docker Desktop and instead defaulting to Hyper-V and then it worked perfectly with the exact same project and configuration.
I could just use Hyper-V but I would rather use WSL2 as many of the other Docker projects I run locally just use WSL2 Docker Desktop and I don't want to have to keep switching back and forth.
This is the output of my container logs: