voi*_*ipp 13 networking docker
我只是好奇,host.docker.internal 主机上正在运行什么?
该服务将包从 docker 容器路由到主机网络上的服务。
但它到底是什么?
我发现这不是网关。
tgo*_*gos 24
我将回答一些我发现的有关Linux
实施的事情。我敢打赌,Windows / Mac 版 Docker 的实现细节会有所不同。
简而言之: 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
Run Code Online (Sandbox Code Playgroud)
--add-host
(适用于容器):它将您在上面看到的最后一行添加到容器中/etc/hosts
,这样就host.docker.internal
解析为 IP 地址host-gateway
host-gateway
(适用于主机):对于典型的 Docker 安装,它通常是172.17.0.1
(默认桥),但可以使用 更改/配置dockerd
,请参阅相关文档:
Run Code Online (Sandbox Code Playgroud)--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
您可以检查添加此功能的 Pull 请求:#40007
该用户描述他做了以下事情:
我做了什么
这个 PR 允许容器通过附加一个特殊的字符串“host-gateway”来连接到 Linux 主机,例如--add-host
,它将--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
东西。 归档时间: |
|
查看次数: |
21708 次 |
最近记录: |