如何启动多接口的docker容器?

时间:2017-08-17 02:48:08

标签: docker networking

我想启动一个带有三个接口的docker容器,所有这些接口都将连接到主机上的一个桥接器。     唯一的解决方案是提供我自己的网络插件。创建容器以配置其网络后,docker守护程序将调用以下接口:

True

func (d *Driver) Join(r *dknet.JoinRequest) (*dknet.JoinResponse, error) 结构中只有一个Endpoint对象,因此上面的调用只能配置一个容器接口。

我不知道如何创建和配置三个容器接口?

1 个答案:

答案 0 :(得分:1)

你需要多次这样做

$ docker network create net1
bdc53c143e89d562761eedfd232620daf585968bc9ae022ba142d17601af6146

$ docker network create net2
d9a72a7a6ee6b61da3c6bb17e312e48888807a5a8c159fd42b6c99d219977559

$ docker network create net3
d2be9628f4fd60587d44967a5813e9ba7c730d24e953368b18d7872731a9478c

$ docker run -it --network net3 ubuntu:16.04 bash

root@cd70c7cbe367:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
90: eth0@if91: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:18:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.24.0.2/16 scope global eth0
       valid_lft forever preferred_lft forever

现在,您的容器仅以net3网络运行。您也可以附加net1net2

$ docker network connect net1 cd70c7cbe367
$ docker network connect net2 cd70c7cbe367

之后检查容器

root@cd70c7cbe367:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
90: eth0@if91: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:18:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.24.0.2/16 scope global eth0
       valid_lft forever preferred_lft forever
92: eth1@if93: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:16:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.22.0.2/16 scope global eth1
       valid_lft forever preferred_lft forever
94: eth2@if95: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:17:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.23.0.2/16 scope global eth2
       valid_lft forever preferred_lft forever

PS:默认情况下容器中缺少ip命令,所以我安装了iproute2打包检查