hack for docker's network
DESCRIPTION
Hack for Docker's Network * ICC(Inter-Container Communication) * iptables rules * pipeworkTRANSCRIPT
Hack for Docker's Network
2014/02/12(水)
@hansode
まずは自己紹介
2
■自己紹介
•吉田将士 / Masahito Yoshida
•株式会社あくしゅ http://axsh.jp/•担当: Wakame-vdc CI環境周りで生活•⇒ 「国産IaaSコントローラ」らしいです
•Twitter: @hansode•GitHub: https://github.com/hansode
3
気付いたら、1年以上、連続活動。
■Docker Contribution
さて、本題へ
5
Network周りを中心に、疑問に思った事を
幾つか検証してみました。
6
事前情報として、Docker
検証環境の内容です。
7
■Docker Host 検証環境
•Linux Distribution:•CentOS 6.5
•Base:•kernel-2.6.32-431.el6.x86_64•bridge-utils-1.2-10.el6.x86_64
•EPEL:•docker-io-0.7.6-2.el6.x86_64•lxc-0.9.0-2.el6.x86_64
•OpenStack:•iproute-2.6.32-130.el6ost.netns.2.x86_64•openvswitch-1.11.0_8ce28d-1.el6ost.x86_64
8
Q: Dockerはコンテナ間通信を制御出来るのか?
9
ドキュメントを確認してみると、制御機能、ありました。
10
ICC:Inter-ContainerCommunication
11
■ ICC
The value of the Docker daemon's icc parameter determines whether containers can communicate with each other over the bridge network.
+ The default, -icc=true allows containers to communicate with each other.+ -icc=false means containers are isolated from each other.
Docker uses iptables under the hood to either accept or drop communication between containers.
http://docs.docker.io/en/latest/use/networking/
-icc=true/false 切り替えでコンテナ間通信を制御する機能
12
■ ICC
The value of the Docker daemon's icc parameter determines whether containers can communicate with each other over the bridge network.
+ The default, -icc=true allows containers to communicate with each other.+ -icc=false means containers are isolated from each other.
Docker uses iptables under the hood to either accept or drop communication between containers.
http://docs.docker.io/en/latest/use/networking/
iptablesでコンテナ間通信を遮断
13
■ ICC
The value of the Docker daemon's icc parameter determines whether containers can communicate with each other over the bridge network.
+ The default, -icc=true allows containers to communicate with each other.+ -icc=false means containers are isolated from each other.
Docker uses iptables under the hood to either accept or drop communication between containers.
http://docs.docker.io/en/latest/use/networking/
iptablesの詳細は無い14
-icc=true, -icc=falseiptablesルール差分、気になりました。
15
気になったので調べてみました。
16
ところで、-icc=true, -icc=falseを設定するには・・・
17
/etc/sysconfig/dockerを修正(RHEL6系の場合)
18
■ICC: /etc/sysconfig/docker
other_args="”
other_args="-icc=false”
default
falseの場合は、-icc=false $ sudo /etc/init.d/docker restart
設定反映の為、Daemonを再起動
19
-icc=true, -icc=falseルール比較する為の
シナリオ
20
■ルール比較のシナリオ
21
■ルール比較のシナリオ
$ sudo /etc/init.d/docker restarticcフラグを指定し、デーモンを再起動
-icc=?
22
■ルール比較のシナリオ
CT1
コンテナ(CT1)を作成
$ sudo docker run -d ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
$ sudo /etc/init.d/docker restart
-icc=?
23
■ルール比較のシナリオ
CT1
ルールを取得
$ sudo iptables -t filter -nL | ¥tee /tmp/iptables.filter.1.log
$ sudo iptables -t nat -nL | ¥tee /tmp/iptables.nat.1.log
$ sudo docker run -d ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
$ sudo /etc/init.d/docker restart
-icc=?
rule
24
■ルール比較のシナリオ
$ sudo iptables -t filter -nL | ¥tee /tmp/iptables.filter.2.log
$ sudo iptables -t nat -nL | ¥tee /tmp/iptables.nat.2.log
CT1 CT2
$ sudo iptables -t filter -nL | ¥tee /tmp/iptables.filter.1.log
$ sudo iptables -t nat -nL | ¥tee /tmp/iptables.nat.1.log
$ sudo docker run -d ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
$ sudo docker run -d ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
$ sudo /etc/init.d/docker restartコンテナ(CT2)を作成
-icc=?
rule
25
■ルール比較のシナリオ
$ sudo iptables -t filter -nL | ¥tee /tmp/iptables.filter.2.log
$ sudo iptables -t nat -nL | ¥tee /tmp/iptables.nat.2.log
CT1 CT2
$ sudo iptables -t filter -nL | ¥tee /tmp/iptables.filter.1.log
$ sudo iptables -t nat -nL | ¥tee /tmp/iptables.nat.1.log
$ sudo docker run -d ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
$ sudo docker run -d ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
$ sudo /etc/init.d/docker restartルールを取得
-icc=?
rule rule
26
■ルール比較のシナリオ
CT1 CT2
-icc=true
diff
rule rule
CT1 CT2
-icc=false
rule rule
ルールを比較
27
結果は・・・
28
■ルール比較結果
$ cat iptables.filter.1.logChain INPUT (policy ACCEPT)target prot opt source destination
Chain FORWARD (policy ACCEPT)target prot opt source destinationACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHEDACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT)target prot opt source destination
$ cat iptables.filter.1.logChain INPUT (policy ACCEPT)target prot opt source destination
Chain FORWARD (policy ACCEPT)target prot opt source destinationDROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHEDDROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT)target prot opt source destination
-icc=true -icc=false
ACCEPT がDROP へ変化29
コンテナ内の通信が遮断されてるか、確認してみる。
30
■コンテナ間通信遮断を確認
CT1 CT2
-icc=false
期待値は、パケットは行き来せず、
DROPされる事。31
■コンテナ間通信遮断を確認
CT1 CT2
-icc=false
sshコマンドを実行すると・・・
32
■コンテナ間通信遮断を確認
CT1 CT2
-icc=false
root@a819b0a1729c:~# ssh 172.17.0.7The authenticity of host '172.17.0.7 (172.17.0.7)' can't be established.ECDSA key fingerprint is 88:f4:ba:25:54:47:ce:8c:63:54:fa:17:53:31:d5:6d.Are you sure you want to continue connecting (yes/no)?
おや・・?DROPされてない?!
33
Q:sysctlは、どうなっている?
34
■コンテナ間通信遮断を確認
CT1 CT2
-icc=false
# Disable netfilter on bridges.net.bridge.bridge-nf-call-ip6tables = 0net.bridge.bridge-nf-call-iptables = 0net.bridge.bridge-nf-call-arptables = 0
file:///etc/sysctl.conf
RHEL6系の場合、Bridge経由パケットがフィルタ対象外。
$ sysctl net.bridge.bridge-nf-call-iptablesnet.bridge.bridge-nf-call-iptables = 0
35
■コンテナ間通信遮断を確認
CT1 CT2
-icc=false
# Disable netfilter on bridges.net.bridge.bridge-nf-call-ip6tables = 0net.bridge.bridge-nf-call-iptables = 1net.bridge.bridge-nf-call-arptables = 0
file:///etc/sysctl.conf
net.bridge.bridge-nf-call-iptables = 1を設定すると、DROPされるようになる。
$ sudo –w sysctl net.bridge.bridge-nf-call-iptables=1net.bridge.bridge-nf-call-iptables = 1
$ sudo sysctl -p
36
ICCをおさらい
37
■ ICCをおさらい: iptables rule
The value of the Docker daemon's icc parameter determines whether containers can communicate with each other over the bridge network.
+ The default, -icc=true allows containers to communicate with each other.+ -icc=false means containers are isolated from each other.
Docker uses iptables under the hood to either accept or drop communication between containers.
http://docs.docker.io/en/latest/use/networking/
rule内容が、-icc=true時はACCEPT-icc=false時はDROP 38
iccフラグにより、コンテナ間通信が
遮断される事は分かった。
39
しかし、
40
特定コンテナ間通信は、許可したい・・・
41
ドキュメントを確認してみると、要望を満たす機能を発見。
42
Link Containers
43
■ Link Containers
http://docs.docker.io/en/latest/use/working_with_links_names/
Daemonのフラグ-icc=false、-nameフラグと-linkフラグを組み合わせて使う事が分かる。
Container Naming:You can now name your container by using the -name flag.
Links: service discovery for dockerLinks allow containers to discover and securely communicate with each other by using the flag -link name:alias. Inter-container communication can be disabled with the daemon flag -icc=false. With this flag set to false, Container A cannot access Container B unless explicitly allowed via a link. This is a huge win for securing your containers. When two containers are linked together Dockercreates a parent child relationship between the containers.
44
この関係を図とコマンドにしてみると、
45
-icc=false
■ Link Containers
-icc=false 指定Dockerホスト
46
-icc=false
■ Link Containers
$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D
-name 指定でコンテナを作成。
47
-icc=false
CT01-name ct01
■ Link Containers
$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D
48
-icc=false
CT01-name ct01
■ Link Containers
$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D
$ sudo docker run -d ¥-name ct02 ¥-link ct01:sshd ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D
-link 指定でコンテナを作成。
49
-icc=false
CT02
CT01-name ct01
-link ct01:sshd
■ Link Containers
$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D
$ sudo docker run -d ¥-name ct02 ¥-link ct01:sshd ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D
CT01からの接続は、受け入れる。
50
-icc=false
CT02
CT01-name ct01
-link ct01:sshd
■ Link Containers
$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D
$ sudo docker run -d ¥-name ct02 ¥-link ct01:sshd ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D
CT03からの接続は、拒否。
CT03
51
-icc=false
CT02
CT01-name ct01
-link ct01:sshd
■ Link Containers
この関係はdocker psで確認出来る。
52
-icc=false
CT02
CT01-name ct01
-link ct01:sshd
■ Link Containers
$ sudo docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES1e25390d1efd sshd:latest /usr/sbin/sshd -D Less than a second ago Up Less than a second 22/tcp ct026d161816ac23 sshd:latest /usr/sbin/sshd -D 1 seconds ago Up Less than a second 0.0.0.0:49153->22/tcp ct01,ct02/sshd
NAMESct02ct01,ct02/sshd
実は、接続元ノード情報ではなく、接続先ノード情報が表示されてる。
53
検証をしてたら、nameの制約に遭遇。
54
-name <name>は、再利用不可能?
55
■ nameの制約
-icc=false
CT01-name ct01
$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D
繰り返し検証する為、同じnameを使いまわそうとしたら、
$ sudo docker kill $(sudo docker ps -q)
56
■ nameの制約
-icc=false
CT01-name ct01
$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D
$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D
$ sudo docker kill $(sudo docker ps -q)
コンテナ作成時に、エラーが発生。57
■ nameの制約
-icc=false
CT01-name ct01
$ sudo docker run -p 22 -d -name ct01 sshd /usr/sbin/sshd -D2014/02/12 04:54:08 Error: create: Abort due to constraint violation: constraint failed
一度使ったnameは、再利用出来ないと言う隠れた制約が存在。
58
今の所、-name <name>は、
ユニークにしておいた方が良い。
59
linkとnameの話に戻します。
60
-icc=false
CT02
CT01-name ct01
-link ct01:sshd
■ Link Containers
$ sudo docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES1e25390d1efd sshd:latest /usr/sbin/sshd -D Less than a second ago Up Less than a second 22/tcp ct026d161816ac23 sshd:latest /usr/sbin/sshd -D 1 seconds ago Up Less than a second 0.0.0.0:49153->22/tcp ct01,ct02/sshd
NAMESct02ct01,ct02/sshd
実は、接続元ノード情報ではなく、接続先ノード情報が表示されてる。
61
Q:この時のiptables ruleは、どうなっている?
62
■反映されてるiptables rule
Chain INPUT (policy ACCEPT)target prot opt source destination
Chain FORWARD (policy ACCEPT)target prot opt source destinationACCEPT tcp -- 172.17.0.4 172.17.0.5 tcp spt:22ACCEPT tcp -- 172.17.0.5 172.17.0.4 tcp dpt:22DROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstateRELATED,ESTABLISHEDDROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstateRELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT)target prot opt source destination
-icc=false
CT02
CT01-name ct01
-link ct01:sshd
linkフラグが影響を与えたルール63
■反映されてるiptables rule
Chain INPUT (policy ACCEPT)target prot opt source destination
Chain FORWARD (policy ACCEPT)target prot opt source destinationACCEPT tcp -- 172.17.0.4 172.17.0.5 tcp spt:22ACCEPT tcp -- 172.17.0.5 172.17.0.4 tcp dpt:22DROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstateRELATED,ESTABLISHEDDROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstateRELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT)target prot opt source destination
-icc=false
CT02
CT01-name ct01
-link ct01:sshd
ところで、”tcp spt:22”・・?64
■反映されてるiptables rule
Chain INPUT (policy ACCEPT)target prot opt source destination
Chain FORWARD (policy ACCEPT)target prot opt source destinationACCEPT tcp -- 172.17.0.4 172.17.0.5 tcp spt:22ACCEPT tcp -- 172.17.0.5 172.17.0.4 tcp dpt:22DROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstateRELATED,ESTABLISHEDDROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstateRELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT)target prot opt source destination
-icc=false
CT02
CT01-name ct01
-link ct01:sshd
これは不要じゃないの・・・?65
■反映されてるiptables rule
Chain INPUT (policy ACCEPT)target prot opt source destination
Chain FORWARD (policy ACCEPT)target prot opt source destinationACCEPT tcp -- 172.17.0.4 172.17.0.5 tcp spt:22ACCEPT tcp -- 172.17.0.5 172.17.0.4 tcp dpt:22DROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstateRELATED,ESTABLISHEDDROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstateRELATED,ESTABLISHED
Chain OUTPUT (policy ACCEPT)target prot opt source destination
-icc=false
CT02
CT01-name ct01
-link ct01:sshd
sshしてみると、案の定、繋がらない。66
Bugっぽいので、Issueを確認の上、
PRを送ってみようと思います。
67
Q:複雑なlink構成すると、どうなるのか?
68
-icc=false
■多段Link構成
CT12
CT01
CT21 CT22
CT11
-icc=false
CT02
CT01
3層構成へ 複数link
69
しかし、この複数link構成、仕様上不可能である事が判明する。
70
その仕様とは、linkフラグは文字列型である事。
71
■多段Link構成
Usage: docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
Run a command in a new container
-a=map[]: Attach to stdin, stdout or stderr-c=0: CPU shares (relative weight)-cidfile="": Write the container ID to the file-d=false: Detached mode: Run container in the background, print new container id-e=[]: Set environment variables-h="": Container host name-i=false: Keep stdin open even if not attached-privileged=false: Give extended privileges to this container-m="": Memory limit (format: <number><optional unit>, where unit = b, k, m or g)-n=true: Enable networking for this container-p=[]: Map a network port to the container-rm=false: Automatically remove the container when it exits (incompatible with -d)-t=false: Allocate a pseudo-tty-u="": Username or UID-dns=[]: Set custom dns servers for the container-v=[]: Create a bind mount with: [host-dir]:[container-dir]:[rw|ro]. If "container-dir" is missing, then docker creates a new volume.-volumes-from="": Mount all volumes from the given container(s)-entrypoint="": Overwrite the default entrypoint set by the image-w="": Working directory inside the container-lxc-conf=[]: Add custom lxc options -lxc-conf="lxc.cgroup.cpuset.cpus = 0,1"-sig-proxy=true: Proxify all received signal to the process (even in non-tty mode)-expose=[]: Expose a port from the container without publishing it to your host-link="": Add link to another container (name:alias)-name="": Assign the specified name to the container. If no name is specific docker will generate a random name-P=false: Publish all exposed ports to the host interfaces
man dockerより
-link="": Add link to another container (name:alias)
これが、-link=[] だったなら・・・
72
と言う事で、現仕様で構成可能なのは、
73
■多段Link構成
-icc=false
CT12
CT01
CT21 CT22
CT11
張れるlinkは1本のみ
74
多段link構成を作ってみる。
75
-icc=false
■多段Link構成
76
-icc=false
■多段Link構成
CT01
$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
77
-icc=false
■多段Link構成
CT12
CT01
CT11
$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
$ sudo docker run -d ¥-name ct11 ¥-link ct01:sshd ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
$ sudo docker run -d ¥-name ct12 ¥-link ct01:sshd ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
78
-icc=false
■多段Link構成
CT12
CT01
CT21 CT22
CT11
$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
$ sudo docker run -d ¥-name ct11 ¥-link ct01:sshd ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
$ sudo docker run -d ¥-name ct12 ¥-link ct01:sshd ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
$ sudo docker run -d ¥-name ct21 ¥-link ct11:sshd ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
$ sudo docker run -d ¥-name ct22 ¥-link ct12:sshd ¥-p 22 dhrp/sshd /usr/sbin/sshd -D
79
-icc=false
■多段Link構成
CT12
CT01
CT21 CT22
CT11
$ sudo docker psNAMESct22ct21ct12,ct22/sshdct11,ct21/sshdct01,ct11/sshd,ct12/sshd,ct21/sshd/sshd,ct22/sshd/sshd
docker psの結果から、NAMES項目のみ表示。
80
-icc=false
■多段Link構成
CT12
CT01
CT21 CT22
CT11
$ sudo docker psNAMESct22ct21ct12,ct22/sshdct11,ct21/sshdct01,ct11/sshd,ct12/sshd,ct21/sshd/sshd,ct22/sshd/sshd
注目すべきは、ct01からct21とct22へのlinkが
張られている事。
81
Q:この時のiptables ruleは、どうなっている?
82
■反映されてるiptables rule
-icc=false
CT12
CT01
CT21 CT22
CT11
Chain FORWARD (policy ACCEPT)target prot opt source destinationACCEPT tcp -- 172.17.0.6 172.17.0.8 tcp spt:22ACCEPT tcp -- 172.17.0.8 172.17.0.6 tcp dpt:22ACCEPT tcp -- 172.17.0.5 172.17.0.7 tcp spt:22ACCEPT tcp -- 172.17.0.7 172.17.0.5 tcp dpt:22ACCEPT tcp -- 172.17.0.4 172.17.0.6 tcp spt:22ACCEPT tcp -- 172.17.0.6 172.17.0.4 tcp dpt:22ACCEPT tcp -- 172.17.0.4 172.17.0.5 tcp spt:22ACCEPT tcp -- 172.17.0.5 172.17.0.4 tcp dpt:22DROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHEDDROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHEDDROP all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
linkフラグが影響を与えたルール83
■反映されてるiptables rule
-icc=false
CT12
CT01
CT21 CT22
CT11
Chain FORWARD (policy ACCEPT)target prot opt source destinationACCEPT tcp -- 172.17.0.6 172.17.0.8 tcp spt:22ACCEPT tcp -- 172.17.0.8 172.17.0.6 tcp dpt:22ACCEPT tcp -- 172.17.0.5 172.17.0.7 tcp spt:22ACCEPT tcp -- 172.17.0.7 172.17.0.5 tcp dpt:22ACCEPT tcp -- 172.17.0.4 172.17.0.6 tcp spt:22ACCEPT tcp -- 172.17.0.6 172.17.0.4 tcp dpt:22ACCEPT tcp -- 172.17.0.4 172.17.0.5 tcp spt:22ACCEPT tcp -- 172.17.0.5 172.17.0.4 tcp dpt:22
Iptables ruleでは、2ノード間のACCEPTルールのみ
である事が分かる。
84
■ICC:まとめ
-icc=false
CT12
CT01
CT21 CT22
CT11
iccフラグでコンテナ間通信を制御可能
nameフラグでコンテナに名前付けが可能
パケットの制御はiptables
linkフラグで2点間通信許可が可能
85
Q:コンテナに狙ったIPアドレスを指定できないのか?
86
A:今のDockerには、割り当て機能が無い。
87
そこで登場するのが、
88
Pipework
89
■ Pipework
Software-Defined Networking for Linux Containers
Pipework lets you connect together containers in arbitrarily complex scenarios.
https://github.com/jpetazzo/pipework
多様なコンテナ間通信を提供
200行弱のシェルスクリプト
90
■ Pipework: Usage
$ pipework br1 $CTID 192.168.1.2/24
https://github.com/jpetazzo/pipework
使い方の1つ、コンテナに狙ったIPアドレスを
指定可能。
91
Pipeworkを動かしてみる。
92
■ Pipework
通常のコンテナ構成図。
CT
docker0
eth0veth0
93
■ Pipework
CT
docker0
eth0veth0
$ pipework br1 $CTID 192.168.1.2/24
Pipeworkを実行。
94
■ Pipework
CT
docker0
eth0veth0
$ pipework br1 $CTID 192.168.1.2/24
vethペアを作成。
eth1veth1
95
■ Pipework
CT
docker0
eth0veth0
br1
eth1veth1
vethをbr1に追加する。
$ pipework br1 $CTID 192.168.1.2/24
96
■ Pipework
CT
docker0
eth0veth0
br1
eth1veth1
eth1にIPアドレスを割り当て。
$ pipework br1 $CTID 192.168.1.2/24
97
■ Pipework
CT
docker0
eth0veth0
br1
eth1veth1
Pipeworkによって追加された新たなデバイス。
98
Pipeworkの他の機能は?
99
■ Pipework
Support Open vSwitchIf you want to attach a container to the Open vSwitch bridge, no problem.
https://github.com/jpetazzo/pipework
Linux Bridgeの代わりに、Open vSwitchを利用可能
100
■ Pipework + Open vSwitch
CT
docker0
eth0veth0
br1
eth1veth1
ここをOpen vSwitch化。
101
■ Pipework + Open vSwitch
CT
docker0
eth0veth0
ovsbr1
eth1veth1
$ pipework ovsbr1 $CTID 192.168.1.2/24
ovsbr1を指定するだけ。
102
ここまで重要なのは、PipeworkはDockerコマンドを一切実行してない事。
103
つまり、Pipeworkが対象にしているのは、
LXCコンテナである事。
104
PipeworkとDockerは、上手く住み分けされている。
105
以上、駆け足で進めて参りました・・・
106
■ Network周りを触ってみて・・・
107
・linkを始め、iptablse周りの実装がまだ枯れてなさそう⇒複数link等、EC2のSecurityGroups相当の機能が必要?
・複数Docker Host構成の場合・本体は、しばらく1ホストしか考慮に入れてなさそう?・ホスト超えした時のlinkは、どうするのか・複数ホスト管理、ネットワーク層管理・ホスト間通信、ホスト超えしたコンテナ間通信・Mesos, Marathon, Serf, Wakame-vdc, OpenVNet…
特にこの領域は、まだまだ発展途上。
ご清聴ありがとうございました
https://twitter.com/hansodehttp://blog.hansode.org/
108