Skip to content
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

host.docker.internal isn't working properly with rancher desktop #3686

Closed
devNaresh opened this issue Dec 27, 2022 · 13 comments
Closed

host.docker.internal isn't working properly with rancher desktop #3686

devNaresh opened this issue Dec 27, 2022 · 13 comments

Comments

@devNaresh
Copy link

devNaresh commented Dec 27, 2022

Actual Behavior

I am trying to reach a service running on my host machine using host.docker.internal and its not working. I can reach same service from rancher desktop wsl maching using localhost.

> ping host.docker.internal # inside rancher-desktop wsl
# Working

> curl localhostl:8000
# {"message":"Hello World"}

> curl 0.0.0.0:8000
# {"message":"Hello World"}

> curl host.docker.internal:8000
# Nothing happens

Steps to Reproduce

Just run any hello word application on host machine or ubuntu wsl machine and try to curl into that

> curl host.docker.internal:8000
# Nothing happens

Result

Max retries exceeded with url

Expected Behavior

> curl host.docker.internal:8000
# {"message":"Hello World"}

Additional Information

No response

Rancher Desktop Version

1.7.0

Rancher Desktop K8s Version

1.24.6

Which container engine are you using?

moby (docker cli)

What operating system are you using?

Windows

Operating System / Build Version

windows 11

What CPU architecture are you using?

x64

Linux only: what package format did you use to install Rancher Desktop?

None

Windows User Only

No response

@devNaresh devNaresh added the kind/bug Something isn't working label Dec 27, 2022
@gunamata
Copy link
Contributor

gunamata commented Jan 9, 2023

@devNaresh , Can you please try creating a firewall rule as described in this faq

After creating the firewall rule, below steps worked for me.

>python -m http.server 8000

In an another terminal,
>rdctl shell
#curl host.docker.internal:8000

@devNaresh
Copy link
Author

devNaresh commented Jan 10, 2023

@gunamata I have created firewall rule but still not working. I am running python server on ubuntu wsl machine and curl in racher desktop shell. I am using windows 11 with latest update of wsl (microsoft store version)

WSL version: 1.0.3.0
Kernel version: 5.15.79.1
WSLg version: 1.0.47
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.963

@gunamata
Copy link
Contributor

@devNaresh , Running the python server on Ubuntu and accessing the end point within rancher desktop shell works for me. I am wondering if it's the anti virus program on your machine or a specific VPN setup you may have, that's causing problems for you. Just to narrow down the investigation a bit, Would you be able to try the same steps by disabling your anti virus and not connecting to VPN, and see if it works?

@devNaresh
Copy link
Author

devNaresh commented Jan 11, 2023

@gunamata i tried with firewall off, still no luck. I am not using any VPN. I also tried on fresh windows install but no luck.
Surprising for me is curl localhost:8000 is working but for some reason host.docker.internal:8000 isn't

@gunamata
Copy link
Contributor

@devNaresh , In my last message, when I mentioned that it worked I actually tried localhost:8000 from the rancher-desktop vm.. I spoke with our networking expert @Nino-K, and it looks it's not a bug that you are not able to access a service running in your WSL Ubuntu via host.docker.internal:8000 from the rancher-desktop VM, as host.docker.internal is meant to resolve to the internal IP address of the host machine and not your WSL distro. @Nino-K might have some additional insights to share with you or a potential workaround that lets you access the service via something other than the localhost

@Nino-K
Copy link
Member

Nino-K commented Jan 11, 2023

Hi @devNaresh if you take a look at the /etc/hosts file inside the rancher-desktop distro you will notice that both host.rancher-desktop.internal and host.docker.internal are mapped to wsl's interface IP address on your windows machine. This is by design to allow applications to access the host using either host.rancher-desktop.internal or host.docker.internal.

Since the WSL network stack is shared across all the distros by default, you can access the services that are hosted on other distros using localhost, or alternatively, you can add your own desired domain name in the /etc/host to represent localhost. e.g vm.rancher-desktop.internal.

@Nino-K Nino-K removed the kind/bug Something isn't working label Jan 11, 2023
@Nino-K
Copy link
Member

Nino-K commented Jan 12, 2023

@devNaresh I'm going to close this issue, feel free to re-open it if you encounter anything additional.

@Nino-K Nino-K closed this as completed Jan 12, 2023
@gediminasre
Copy link

gediminasre commented May 27, 2023

Hi @Nino-K, I am not able to make host.docker.internal or any other host to work. I have containers running and from one of the containers I am trying to call a REST API at http://localhost:8080. My application is started locally, not as a container. Having exactly the same setup with Docker Desktop, I was able to call my local service from container via host.docker.internal:8080, but it does not work with Rancher Desktop. I tried host.docker.internal:8080, localhost:8080, 0.0.0.0:8080, 127.0.0.1:8080. Any advice?

/etc/hosts file contains this:
127.0.0.1 localhost

127.0.0.1 auth-server

192.168.1.92 host.docker.internal
192.168.1.92 gateway.docker.internal

127.0.0.1 kubernetes.docker.internal

@davidbarrowsatasos
Copy link

I found ticking the "enable networking tunnel" under Rancher Desktop > File > Preferences > Network solved the problem for me; now I am able to hit "localhost" ... https://superuser.com/questions/1750492/unable-to-resolve-localhost-after-having-installed-rancher-desktop

@gauravmanerkar
Copy link

HI @davidbarrowsatasos
I am using Mac and and facing connection issue with host.docker.internal. How do i get this working? How to find correct ip address?

@davidbarrowsatasos
Copy link

davidbarrowsatasos commented Jul 3, 2024

Hi @gauravmanerkar I am just a user who posted something on this issue to share the experience I had which I felt was related. I don't represent Rancher. It appears @Nino-K is more closely involved with this project.

@jandubois
Copy link
Member

@gauravmanerkar Please file a new bug with the complete information about your configuration, what you have done, and how it failed for you.

Just because part of the error message is the same doesn't mean that the root cause is the same.

Also adding to a closed issue means that the comment will be lost unless somebody responds to it right away because of an email notification. But in the issue list it is still marked as resolved.

@ssuarez-kairosds
Copy link

having the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants