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

Not able to connect to host from within docker container using host.docker.internal #7611

Open
jochenhebbrecht opened this issue Oct 9, 2024 · 2 comments
Labels
area/networking kind/bug Something isn't working parity/project Feature is available from other projects triage/need-to-repro Needs to be reproduced by dev team

Comments

@jochenhebbrecht
Copy link

jochenhebbrecht commented Oct 9, 2024

Actual Behavior

When trying to do a DNS lookup of the hostname host.docker.internal, a faulty IP address is being returned

Steps to Reproduce

  • create a Docker compose file with following contents:
services:
    ubuntu
        image: ubuntu
        extra_hosts:
            - "host.docker.internal:host-gateway"
  • start up docker-compose config using
docker-compose up
  • get into the Docker container using
docker exec -it docker-ubuntu-1 bash
  • install curl using
apt update
apt install curl
  • perform a curl towards the Docker host (it doesn't matter if there's something running or not - it's the DNS lookup that goes wrong)
curl -vvv host.docker.internal
*   Trying 172.17.0.1:80...

Result

The 172.17.0.1 is not the correct IP. This is not the IP of the host machine. If I rerun the whole exercise but without:

        extra_hosts:
            - "host.docker.internal:host-gateway"

and I try to do a curl again, I actually get to the correct IP. Unfortunately, these lines are in our Docker compose file because we have a shared configuration with Linux users

Expected Behavior

When resolving host.docker.internal, a DNS lookup should return the correct IP address of the hostmachine

Additional Information

This is working perfectly fine with Docker Desktop. We ran into this issue as we switched to Rancher Desktop

Rancher Desktop Version

1.16.0

Rancher Desktop K8s Version

N/A

Which container engine are you using?

moby (docker cli)

What operating system are you using?

macOS

Operating System / Build Version

macOS Sequioa 15.0.1

What CPU architecture are you using?

arm64 (Apple Silicon)

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

None

Windows User Only

No response

@Nino-K
Copy link
Member

Nino-K commented Oct 11, 2024

This issue may arise because Rancher Desktop does not recognize the special variable host-gateway. We have an issue to address this here. In the meantime, a quick workaround is to replace the special variable with an IP address."

@jochenhebbrecht
Copy link
Author

@Nino-K thanks for coming back to me on this one. This explains indeed the behaviour we noticed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/networking kind/bug Something isn't working parity/project Feature is available from other projects triage/need-to-repro Needs to be reproduced by dev team
Projects
None yet
Development

No branches or pull requests

3 participants