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

标签 windows docker hyper-v

我有 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 版 Dockerneither 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 上的以下相关问题:

  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

关于Windows 使用 --network=host 运行 docker 并使用 127.0.0.1 访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48915458/

相关文章:

java - 数据类型为 `TIMESTAMP(6) with Local Time Zone` 的 oracle 11g 在 csv 中存档了 Windows 和 Linux 中的不同数据

c++ - Windows WMI - Win32_ProcessStartTrace 和 __InstanceCreationEvent 之间的区别(和顺序)是什么?

Docker/SAM 本地 aws sdk 的请求因 (InvalidSignatureException) 而失败

firebase - 如何在 Google Cloud Build 上部署带有 env vars 的 Vue.js 应用程序?

networking - 在 Docker for Windows 中无法连接到容器 IP 地址

service - Hyper-V 无法连接到本地服务器(Windows 10 主机)

c++ - 如何在 GDI 中转换一个简单的位图

windows - 在命令行上从 Windows 批处理文件执行远程服务器 php 脚本

docker - 检查更新的 Docker 镜像构建

Hyper-v:无法将值\n“链接到 VHD 文件”转换为类型 "Microsoft.HyperV.PowerShell.ControllerType"