[英]What is running on host.docker.internal host?
我只是好奇,host.docker.internal 主機上運行的是什么?
此服務將包從 docker 容器路由到主機網絡上的服務。
但它到底是什么?
我發現它不是網關。
我將回答一些關於Linux
實現的發現。 我敢打賭,Docker for Windows / Mac 的實現細節會有所不同。
簡而言之: host.docker.internal
是一個名稱。 在您的主機上運行並綁定到也設置為 Docker 守護進程host-gateway
的網絡接口的每個服務,都可以從位於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
:它將您在上面看到的最后一行添加到容器的/etc/hosts
中,這樣host.docker.internal
解析為host-gateway
的 IP 地址
host-gateway
:通常是172.17.0.1
(默認網橋),但也可以使用dockerd
進行配置,請參閱相關 文檔👇:
--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
您可以檢查添加此功能的拉取請求: #40007
用戶描述他做了以下事情:
我做了什么
此 PR 允許容器通過將特殊字符串“host-gateway”附加到--add-host
來連接到 Linux 主機,例如--add-host=host.docker.internal:host-gateway
添加host.docker.internal
DNS 條目在/etc/hosts
中並將其映射到host-gateway-ip
。
此 PR 還添加了一個守護進程標志調用host-gateway-ip
,默認為默認網橋 IP 。
Docker Desktop 需要將此字段設置為主機代理 IP,以便可以將 host.docker.internal 的 DNS 請求路由到 VPNkit
我認為這一切背后的歷史或多或少如下:
host.docker.internal
東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.