问题描述
我有Windows 10专业版,正在尝试使用网络模式主机运行docker.
I have windows 10 pro and I'm trying to run a docker with network mode host.
我的问题是我无法运行docker并使用主机ip而不是127.0.0.1而不是ip(在linux中,它的工作原理不同)来访问它.
my issue is that I can't run a docker and access it using the host ip not 127.0.0.1 and not the ip (in linux it works differently).
看起来hyper v拥有自己的网络,无法使用主机ip来访问
looks like the hyper v has it's own network that not accessible using the host 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
如果我将端口设置为而不是网络模式主机,则它可以正常工作
so there is no ports as expected but and no errors.When I'm trying to open the browser using 127.0.0.1 I'm getting ERR_CONNECTION_REFUSED
if I set ports to instead of network mode host it is working
docker run -d -p 80:80 nginx
超级v以太网适配器vEthernet(DockerNAT):
Hyper v Ethernet adapter vEthernet (DockerNAT):
Connection-specific DNS Suffix . :
IPv4 Address. . . . . . . . . . . : 10.0.75.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . .
备注:
- 在Hyper v虚拟交换机管理器中将网络更改为外部网络-无济于事
- 防火墙已禁用
有什么想法如何在Windows中使用网络模式主机吗?
any idea how to work with network mode host in windows?
推荐答案
不幸的是,主机网络是不可用对于适用于Windows的Docker 和 macvlan 联网也不是.如果您不习惯 Hyper-V ,请考虑使用 DockerWindows上的工具箱.
Unfortunately host networking is not available for Docker for Windows and neither is macvlan networking. If you are not stuck on Hyper-V, consider using Docker Toolbox on Windows.
引用自: https://docs.docker.com/network/网络教程主机/#前提条件
还可以在GitHub上查看以下相关问题:
Also see the following related issues on GitHub:
- https://github.com/docker/for-win/issues/1644
- https://github.com/docker/for-win/issues/937
- https://github.com/docker/for-win/issues/543
- https://github.com/docker/for-mac/issues/2716
这篇关于Windows使用--network = host运行docker并使用127.0.0.1进行访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!