适用于Windows Hyper V默认交换机IP的Docker

时间:2019-08-15 06:28:19

标签: windows docker

Hyper V默认交换机IP在C类和D类之间更改,因此,每次重新启动后,您将获得172.17.x.x或192.168.x.x。 到目前为止,这似乎是我可以阅读的所有Windows 10安装的众所周知的“功能”。

我的问题是,如果Hyper Default开关保持在172.17.x.x上,为什么开箱即用且没有任何其他docker网络桥的运行中的Docker容器无法与Internet通信

仅当我获得192.168.x.x时它才有效。我认为原因是Docker默认开关也是172.x.x.x。

关于Windows 10上Hyper V Default开关的当前行为,如何为正在运行的容器配置配置稳定的网络?

路线打印-输出:

===========================================================================
Schnittstellenliste
  8...54 bf 64 a6 c1 0a ......Intel(R) Ethernet Connection (2) I219-LM
  9...00 15 5d e5 81 12 ......Hyper-V Virtual Ethernet Adapter #2
 20...00 50 56 c0 00 01 ......VMware Virtual Ethernet Adapter for VMnet1
  2...00 50 56 c0 00 08 ......VMware Virtual Ethernet Adapter for VMnet8
  1...........................Software Loopback Interface 1
 21...96 15 9f 09 b1 88 ......Hyper-V Virtual Ethernet Adapter
===========================================================================

IPv4-Routentabelle
===========================================================================
Aktive Routen:
     Netzwerkziel    Netzwerkmaske          Gateway    Schnittstelle Metrik
          0.0.0.0          0.0.0.0        10.8.32.1      10.8.40.242      6
        10.0.75.0    255.255.255.0   Auf Verbindung         10.0.75.1    271
        10.0.75.1  255.255.255.255   Auf Verbindung         10.0.75.1    271
      10.0.75.255  255.255.255.255   Auf Verbindung         10.0.75.1    271
        10.8.32.0    255.255.240.0   Auf Verbindung       10.8.40.242    259
      10.8.40.242  255.255.255.255   Auf Verbindung       10.8.40.242    259
      10.8.47.255  255.255.255.255   Auf Verbindung       10.8.40.242    259
        127.0.0.0        255.0.0.0   Auf Verbindung         127.0.0.1    331
        127.0.0.1  255.255.255.255   Auf Verbindung         127.0.0.1    331
  127.255.255.255  255.255.255.255   Auf Verbindung         127.0.0.1    331
     192.168.60.0    255.255.255.0   Auf Verbindung      192.168.60.1    291
     192.168.60.1  255.255.255.255   Auf Verbindung      192.168.60.1    291
   192.168.60.255  255.255.255.255   Auf Verbindung      192.168.60.1    291
  192.168.137.144  255.255.255.240   Auf Verbindung   192.168.137.145   5256
  192.168.137.145  255.255.255.255   Auf Verbindung   192.168.137.145   5256
  192.168.137.159  255.255.255.255   Auf Verbindung   192.168.137.145   5256
    192.168.254.0    255.255.255.0   Auf Verbindung     192.168.254.1    291
    192.168.254.1  255.255.255.255   Auf Verbindung     192.168.254.1    291
  192.168.254.255  255.255.255.255   Auf Verbindung     192.168.254.1    291
        224.0.0.0        240.0.0.0   Auf Verbindung         127.0.0.1    331
        224.0.0.0        240.0.0.0   Auf Verbindung      192.168.60.1    291
        224.0.0.0        240.0.0.0   Auf Verbindung     192.168.254.1    291
        224.0.0.0        240.0.0.0   Auf Verbindung         10.0.75.1    271
        224.0.0.0        240.0.0.0   Auf Verbindung       10.8.40.242    259
        224.0.0.0        240.0.0.0   Auf Verbindung   192.168.137.145   5256
  255.255.255.255  255.255.255.255   Auf Verbindung         127.0.0.1    331
  255.255.255.255  255.255.255.255   Auf Verbindung      192.168.60.1    291
  255.255.255.255  255.255.255.255   Auf Verbindung     192.168.254.1    291
  255.255.255.255  255.255.255.255   Auf Verbindung         10.0.75.1    271
  255.255.255.255  255.255.255.255   Auf Verbindung       10.8.40.242    259
  255.255.255.255  255.255.255.255   Auf Verbindung   192.168.137.145   5256
===========================================================================
Ständige Routen:
  Keine

IPv6-Routentabelle
===========================================================================
Aktive Routen:
 If Metrik Netzwerkziel             Gateway
  1    331 ::1/128                  Auf Verbindung
  1    331 ff00::/8                 Auf Verbindung
===========================================================================
Ständige Routen:
  Keine

1 个答案:

答案 0 :(得分:0)

这是由于Default Switch导致的。 我们可以通过创建单独的交换机并使用NATTING对其进行配置

Open Hyper-V Manager (Windows search : “Hyper-V …”)
Go to Virtual Switch Manager on the right side.
Go to DockerNAT then choose Connection type -> to External network -> #which interface you deside.

创建了一个Windows nanoserver容器,为Docker配置了NIC到NAT的网卡,并且可以在Windows 10机器上正常工作

PS C:> docker运行mcr.microsoft.com/windows/nanoserver:1809 ping google.com

Pinging google.com [216.58.203.206] with 32 bytes of data: 
Reply from 216.58.203.206: bytes=32 time=56ms TTL=55 
Reply from 216.58.203.206: bytes=32 time=58ms TTL=55 
Reply from 216.58.203.206: bytes=32 time=38ms TTL=55 
Ping statistics for 216.58.203.206: Packets: Sent = 4, 
Received = 4, Lost = 0 (0% loss), 

此外,我不确定为什么要挂它。您使用的是unix Containers还是Win?