windows 运行 docker 使用 --network=host 并使用 127.0.0.1 访问

windows run docker with --network=host and access with 127.0.0.1

我有 windows 10 pro,我正在尝试 运行 docker 网络模式主机。

我的问题是我不能 运行 a 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 . . . . . . . . . 

备注:

知道如何在 windows 中使用网络模式主机吗?

不幸的是 主机 网络是 not available for Docker for Windows and neither is macvlan networking. If you are not stuck on Hyper-V, consider using 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 上的以下相关问题:

  1. https://github.com/docker/for-win/issues/1644
  2. https://github.com/docker/for-win/issues/937
  3. https://github.com/docker/for-win/issues/543
  4. https://github.com/docker/for-mac/issues/2716