繁体   English   中英

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

[英]windows run docker with --network=host and access with 127.0.0.1

我有 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 中使用网络模式主机吗?

不幸的是主机网络是不可用泊坞窗为Windows既不是macvlan网络。 如果您没有坚持使用Hyper-V ,请考虑在 Windows 上使用Docker Toolbox

引自: https : //docs.docker.com/network/network-tutorial-host/#prerequisites

主机网络驱动程序仅适用于 Linux 主机,在 Docker for Mac、Docker for Windows 或 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM