host运行docker并使用127

host运行docker并使用127

本文介绍了Windows使用--network = host运行docker并使用127.0.0.1进行访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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_REFUSEDif 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 . . . . . . . . .

备注:

07-30 19:30