如何在Docker中为多个覆盖网络指定静态IP地址

时间:2016-03-11 20:44:18

标签: docker

所以我创建了两个覆盖网络,如下所示:

docker network create --driver overlay --subnet 10.40.1.0/16 --internal net1
docker network create --driver overlay --subnet 10.50.1.0/16 --internal net2

现在我想运行一个容器,为每个网络分配一个静态IP地址

怎么做?泊坞窗不接受多个--net flags

1 个答案:

答案 0 :(得分:2)

您可以启动停靠状态的docker,连接网络,然后才启动它:

docker create --name busybox -ti --net net1 --ip 10.40.1.0 busybox ifconfig
docker network connect --ip 10.50.1.0 net2 busybox
docker start -ai busybox

eth0      Link encap:Ethernet  HWaddr 02:42:0A:28:00:05
          inet addr:10.40.0.5  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:aff:fe28:5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1450  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:90 (90.0 B)  TX bytes:90 (90.0 B)

eth1      Link encap:Ethernet  HWaddr 02:42:0A:32:00:05
          inet addr:10.50.0.5  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:aff:fe32:5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1450  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:90 (90.0 B)  TX bytes:90 (90.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)