Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent to Docker Desktop's 'host.docker.internal' in Rancher Desktop

Tags:

docker

rancher

For Docker Desktop inside a container, the DNS name host.docker.internal resolves to an IP address allowing network access to the host. Is there something similar when using Rancher Desktop?

Assuming a running container (e.g the alpine image) in Docker Desktop it's possible to run

docker exec alpine-container ping -c 2 host.docker.internal

Update: This has been resolved and released with v1.0.1 as it seems.

like image 780
Andi Avatar asked Dec 04 '25 13:12

Andi


1 Answers

When using the dockerd (moby) container runtime in Rancher Desktop, adding --add-host=host.docker.internal:host-gateway to your docker run command will achieve this behavior.

docker run -it --add-host=host.docker.internal:host-gateway alpine cat /etc/hosts

Or for docker-compose:

# docker-compose.yml
  my_app:
    image: ...
    extra_hosts:
      - "host.docker.internal:host-gateway"

https://megamorf.gitlab.io/2020/09/19/access-native-services-on-docker-host-via-host-docker-internal/#implementation

However I don't believe this will work when using Rancher Desktop with containerd as the container runtime.

like image 88
Eric B Avatar answered Dec 07 '25 11:12

Eric B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!