我有 Windows 10 专业版,我正在尝试使用网络模式主机运行 docker。
我的问题是我无法运行 docker 并使用主机 ip 访问它而不是 127.0.0.1 而不是 ip(在 linux 中它的工作方式不同)。
看起来 hyper v 有自己的网络,无法使用主机 ip 访问
docker run -d --network=host nginx
输出:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8edd86bf292b nginx "nginx -g 'daemon of…" 3 seconds ago Up 2 seconds happy_curie
所以没有预期的端口,但也没有错误。
当我尝试使用 127.0.0.1 打开浏览器时,我得到了 ERR_CONNECTION_REFUSED
如果我将端口设置为而不是网络模式主机它正在工作
docker run -d -p 80:80 nginx
Hyper v 以太网适配器 vEthernet (DockerNAT):
Connection-specific DNS Suffix . :
IPv4 Address. . . . . . . . . . . : 10.0.75.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . .
备注:
- 将 hyper v 虚拟交换机管理器中的网络更改为外部网络 - 无济于事
- 防火墙被禁用
知道如何在 Windows 中使用网络模式主机吗?
最佳答案
不幸的是主机网络是not available适用于 Windows 版 Docker 和 neither is macvlan 网络。如果您不在 Hyper-V 上,请考虑使用 Docker Toolbox在 Windows 上。
引自:https://docs.docker.com/network/network-tutorial-host/#prerequisites
The host networking driver only works on Linux hosts, and is not supported on Docker for Mac, Docker for Windows, or Docker EE for Windows Server.
另请参阅 GitHub 上的以下相关问题:
关于Windows 使用 --network=host 运行 docker 并使用 127.0.0.1 访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48915458/