从docker容器访问主机虚拟机

从docker容器访问主机虚拟机

我在桥接网络中有两个可以通信的 docker 容器。我希望其中一个容器能够与 hyper-V vm 通信。

这是来自虚拟机的 ipconfig:

eth0      Link encap:Ethernet  HWaddr 00:15:5d:02:02:08
          inet addr:192.168.2.26  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: 2a02:85f:1f0a:eb00:215:5dff:fe02:208/64 Scope:Global
          inet6 addr: fe80::215:5dff:fe02:208/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:830670 errors:0 dropped:186 overruns:0 frame:0
          TX packets:338902 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:283705473 (283.7 MB)  TX bytes:79909804 (79.9 MB)

这是来自 docker 的网络检查:

[                                                                                                     
    {                                                                                                 
        "Name": "docker_xxx_network",                                                        
        "Id": "a1da890e08caafa97a02364ef0b92fbec1bf8f9cdbfbdee9ba873550f41f8583",                     
        "Created": "2018-10-26T19:57:13.5982985Z",                                                    
        "Scope": "local",                                                                             
        "Driver": "bridge",                                                                           
        "EnableIPv6": false,                                                                          
        "IPAM": {                                                                                     
            "Driver": "default",                                                                      
            "Options": null,                                                                          
            "Config": [                                                                               
                {                                                                                     
                    "Subnet": "192.168.0.0/20",                                                       
                    "Gateway": "192.168.0.1"                                                          
                }                                                                                     
            ]                                                                                         
        },                                                                                            
        "Internal": false,                                                                            
        "Attachable": true,                                                                           
        "Ingress": false,                                                                             
        "ConfigFrom": {                                                                               
            "Network": ""                                                                             
        },                                                                                            
        "ConfigOnly": false,                                                                          
        "Containers": {                                                                               
            "4e6e909d6c1b56482c852769b941a9869f6e053ac4f7a384fba002648ff30885": {                     
                "Name": "xxxAdmin_database",                                                      
                "EndpointID": "d3b5d1467003932b37fd0c5427b82da99bce8eddb5e2908d0877e5c1be7dc901",     
                "MacAddress": "02:42:c0:a8:00:02",                                                    
                "IPv4Address": "192.168.0.2/20",                                                      
                "IPv6Address": ""                                                                     
            },                                                                                        
            "b0f6cbf8c0cd5fa4fc15381c021169cb9fa72da19f9c1d969a029a1355eb9802": {                     
                "Name": "xxxAdmin_app",                                                           
                "EndpointID": "6217f698656d14226b3f2a1510bb7c5d68e847d193d40e864287a4a2f33d4c8c",     
                "MacAddress": "02:42:c0:a8:00:03",                                                    
                "IPv4Address": "192.168.0.3/20",                                                      
                "IPv6Address": ""                                                                     
            }                                                                                         
        },                                                                                            
        "Options": {},                                                                                
        "Labels": {                                                                                   
            "com.docker.compose.network": "xxxAdmin_network",                                     
            "com.docker.compose.project": "docker",                                                   
            "com.docker.compose.version": "1.22.0"                                                    
        }                                                                                             
    }                                                                                                 
]       

我的主机

Windows IP Configuration


Ethernet adapter vEthernet (DockerNAT):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::9827:2321:c8f6:f97d%11
   IPv4 Address. . . . . . . . . . . : 10.0.75.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Ethernet adapter vEthernet (External):

   Connection-specific DNS Suffix  . :
   IPv6 Address. . . . . . . . . . . : 2a02:85f:1f0a:eb00:40bf:6403:206:2742
   Temporary IPv6 Address. . . . . . : 2a02:85f:1f0a:eb00:357b:9cb:c37f:88d9
   Link-local IPv6 Address . . . . . : fe80::40bf:6403:206:2742%19
   IPv4 Address. . . . . . . . . . . : 192.168.2.2
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : fe80::1%19
                                       192.168.2.1

Ethernet adapter vEthernet (Default Switch):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::b8cd:8eaf:c2de:f6d3%25
   IPv4 Address. . . . . . . . . . . : 192.168.101.145
   Subnet Mask . . . . . . . . . . . : 255.255.255.240
   Default Gateway . . . . . . . . . :

我不太了解,谁能告诉我解决办法?谢谢

答案1

我刚刚解决了。我将 docker 网络从 type 改为bridgetype host

相关内容