I'm just curious, what is running on host.docker.internal host?
This service routes packages from docker container to services on host network.
But what exactly is it ?
I found out that its not gateway.
I'll answer with a few things that I've found regarding the Linux
implementation. I bet that the implementation details for Docker for Windows / Mac will be different.
In short: host.docker.internal
is a Name. Every service that runs on your host and binds to the network interface that is also set as the Docker Daemon host-gateway
, it can be accessed from inside a container at host.docker.internal:[service_port]
.
$ docker run -it --rm --add-host=host.docker.internal:host-gateway alpine
/ # cat /etc/hosts
127.0.0.1 localhost
... (it has a few other lines here) ...
172.17.0.1 host.docker.internal 👈👈👈
--add-host
: it adds the last the line you see above to the container's /etc/hosts
and this way host.docker.internal
resolves to the IP address of host-gateway
host-gateway
: usually 172.17.0.1
(default bridge) but also configurable with dockerd
, see the relative docs 👇:
--host-gateway-ip ip IP address that the special 'host-gateway' string in --add-host resolves to. Defaults to the IP address of the default bridge
You can check the Pull request that adds this feature: #40007
The user describes that he did the following:
What I did
This PR allows containers to connect to Linux hosts by appending a special string "host-gateway" to--add-host
eg--add-host=host.docker.internal:host-gateway
which addshost.docker.internal
DNS entry in/etc/hosts
and maps it tohost-gateway-ip
.
This PR also add a daemon flag callhost-gateway-ip
which defaults to the default bridge IP .
Docker Desktop will need to set this field to the Host Proxy IP so DNS requests for host.docker.internal can be routed to VPNkit
I think the history behind all this is more or less the following:
host.docker.internal
thing.More: From inside of a Docker container, how do I connect to the localhost of the machine?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.