我有一个由3个应用程序组成的环境,两个在Windows中运行,一个在Debian中运行。
出于测试目的,我已经用VirtualBox VM (用于运行Debian )在1台PC (运行Windows10)中构建了环境。
以下是详细的网络配置:
主机PC (只使用2 VirtualBox主机适配器):
Ethernet adapter VirtualBox Host-Only Network:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::ec0c:3c16:4f85:1a5e%12
IPv4 Address. . . . . . . . . . . : 192.168.1.11
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.12
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.13
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.14
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.15
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.21
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.22
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.23
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.24
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.25
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.26
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.31
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.32
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.33
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.34
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.1.123
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
Ethernet adapter VirtualBox Host-Only Network #2:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::5d7:813f:a9a:865d%16
IPv4 Address. . . . . . . . . . . : 192.168.1.122
Subnet Mask . . . . . . . . . . . : 255.255.255.248
Default Gateway . . . . . . . . . :VirtualBox VM网络配置:
/etc/网络/接口:
auto lo
iface lo inet loopback
auto eth1
iface eth1 inet static
address 192.168.1.120
netmask 255.255.255.0
gateway 192.168.1.1
auto eth2
allow-hotplug eth2
iface eth2 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
auto eth2:0
iface eth2:0 inet static
address 192.168.1.20
netmask 255.255.255.0
auto eth2:1
iface eth2:1 inet static
address 192.168.1.30
netmask 255.255.255.0Ifconfig输出:
eth0 Link encap:Ethernet HWaddr 08:00:27:a8:08:8b
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
...
eth1 Link encap:Ethernet HWaddr 08:00:27:41:27:73
inet addr:192.168.1.120 Bcast:192.168.1.255 Mask:255.255.255.0
...
eth2 Link encap:Ethernet HWaddr 08:00:27:0d:6b:54
inet addr:192.168.1.10 Bcast:192.168.1.255 Mask:255.255.255.0
...
eth2:0 Link encap:Ethernet HWaddr 08:00:27:0d:6b:54
inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
...
eth2:1 Link encap:Ethernet HWaddr 08:00:27:0d:6b:54
inet addr:192.168.1.30 Bcast:192.168.1.255 Mask:255.255.255.0
...
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
...以下是当前环境下的一些网络交互流程:
这个环境现在运行良好,但是在阅读了关于Docker的文章之后,我计划用使用Docker来代替VirtualBox VM,以减少内存的使用。
我成功地建立了Debian形象,安装库等.
但是,我不知道如何在Docker中安装网络,使其具有与上述VirtualBox VM配置类似的功能。一些令人困惑的观点:
因此,使用Docker建立上述环境似乎非常困难。
如果有人仍然能够使用Docker构建环境,请帮助指出一些方向。
非常感谢!
发布于 2020-11-02 10:39:59
你问的前三个问题是用macvlan网络解决的。您将有容器直接连接到您的网络,就像VM的容器一样。
version: "2.1"
services:
nginx1:
image: nginx
networks:
network_1:
ipv4_address: 10.1.1.115
nginx2:
image: nginx
networks:
network_1:
ipv4_address: 10.1.1.116
networks:
network_1:
driver: macvlan
driver_opts:
parent: enp52s0 # Your network interface name
ipam:
driver: default
config:
- subnet: 10.1.1.0/24
gateway: 10.1.1.1在本例中,我声明了一个名为network_1的macvlan网络,它连接到enp52s0网络接口上。两个nginx容器使用该网络,每个容器都发布自己的静态IP。
现在,如果您想为每个容器分配多个IP,事情就开始变得混乱起来。要分配额外的地址,您需要一个额外的网络,具有自己的IP范围、自己的父网络接口和自己的网关。那实际上是另一个网络。或者你可以考虑一些黑客攻击,比如使用代理容器监听另一个IP,并将流量转发到所需的容器中,但这有点“meh”。我想说的是,除非您愿意重新设计应用程序的连接性,否则VM开销不值得所有的麻烦。
https://stackoverflow.com/questions/64388836
复制相似问题