-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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 access localhost on Windows while running docker on WSL 2 #2568
Comments
FYI you should paste your log between the 3 ticks (`). I believe your error is the same as in #2280. |
@george-gca, thank you for the reply! I've tried to describe everything related to my problem thoroughly in this comment. In short, I've managed to solve the issue but still haven't found a solution that allows me not to disable the following rows in the
|
I'm afraid I can't help much further. When I used WSL 2, I used a local installation (not docker). My current setup is on Ubuntu. |
Are you using docker desktop? If so this might help. |
@george-gca thanks for the recommendation! I'll look into it and get back with feedback. No, I've been using Docker Engine + Docker Compose. |
FYI I was using this technique to launch X applications through VcXsrv long before Windows supported X natively and kept using it as Windows doesn't support the secondary clipboard and has issue with non-US keyboard mappings. This technique stopped working recently - the IP from resolv.conf pings but it is no longer possible to connect to any port. I haven't found a solution for this yet. One workaround I tried was to add the external IP, i.e. the one Windows uses on the local network, but the connection often breaks killing applications at random times. I use this only casually on some relative's PC as I personally use Linux only, therefore I can't tell when this broke exactly, but likely in the last 3-6 months (Windows 11, keeping updated but no preview/early versions). |
I actually fixed it, rather than taking the ip address from resolv.conf I get the default route: $wslrt = wsl bash -c "ip -j route list default" | ConvertFrom-Json
$wslserv = $wslrt.gateway
C:\Windows\System32\wsl.exe ~ -- /usr/bin/env "DISPLAY=${wslserv}:0" /usr/bin/rxvt-unicode The full script is slightly longer, it also gets WSL IP and adds it to allowed xhosts, and it's written as a oneliner... |
Can you provide more detailed information? This might help other users (and also users from other projects that might fall here from search). |
So the technique described in microsoft/WSL#1032 (I'm not sure if the comment anchor was on purpose, I was referring to the ticket itself) - using the DNS resolver's IP address to communicate with the host, i.e. this command from Linux: remoteaddr=$(awk '/nameserver/ {print $2; exit}' /etc/resolv.conf) In powershell it can be captured with: $remoteaddr = wsl bash -c "awk '/nameserver/ {print \`$2; exit}' /etc/resolv.conf" This worked for a while, but not anymore. WSL appears to have changed a bit the networking configuration and while this IP pings, it is no longer possible to use it to access other services. Using the default gateway, OTOH, appears to work now (documented here although I specify the default route and prefer using json - you may have to install remoteaddr=$(ip -j route list default | jq -r '.[].gateway') Or from Powershell (no need for $remoteaddr = (wsl bash -c "ip -j route list default" | ConvertFrom-Json).gateway Alternatively, another way appears to be getting it directly from the HyperV Interface created for WSL - I can't remember where I found about this but the name has apparently changed from This should work regardless of the interface name, as long as there is only one marching the wildcard: $remoteaddr = (Get-NetIPInterface "vEthernet (WSL*)" -AddressFamily IPv4 |Get-NetIPAddress).IPAddress |
Have you checked that your issue isn't already filed?
Bug description
Hi! I've done everything according to the install.md file (meaning, I haven't changed anything in the docker-related files, for example), but still have a problem with the localhost page in my web browser on the Windows side. The docker container itself runs correctly on WSL 2.
How to reproduce the bug
INSTALL.md
file and do everything according to the "Recommended Approach" subsection.http://localhost:8080
. In my case, there's only the "This page isn’t working" inscription.Error messages and logs
The error:
The
docker ps
command output:The
docker logs <container_id>
command output:What operating system are you using?
Windows
Where are you seeing the problem on?
Running locally with Docker
More info
I use Microsoft Windows 10 Pro (10.0.19045 N/A Build 19045) as my main OS and Ubuntu 22.04.4 LTS as the Linux distribution for WSL 2.
The text was updated successfully, but these errors were encountered: