hack for docker's network

108
Hack for Docker's Network 2014/02/12() @hansode

Upload: masahito-yoshida

Post on 08-Sep-2014

23 views

Category:

Technology


0 download

DESCRIPTION

Hack for Docker's Network * ICC(Inter-Container Communication) * iptables rules * pipework

TRANSCRIPT

Page 1: Hack for Docker's Network

Hack for Docker's Network

2014/02/12(水)

@hansode

Page 2: Hack for Docker's Network

まずは自己紹介

2

Page 3: Hack for Docker's Network

■自己紹介

•吉田将士 / Masahito Yoshida

•株式会社あくしゅ http://axsh.jp/•担当: Wakame-vdc CI環境周りで生活•⇒ 「国産IaaSコントローラ」らしいです

•Twitter: @hansode•GitHub: https://github.com/hansode

3

気付いたら、1年以上、連続活動。

Page 4: Hack for Docker's Network

■Docker Contribution

Page 5: Hack for Docker's Network

さて、本題へ

5

Page 6: Hack for Docker's Network

Network周りを中心に、疑問に思った事を

幾つか検証してみました。

6

Page 7: Hack for Docker's Network

事前情報として、Docker

検証環境の内容です。

7

Page 8: Hack for Docker's Network

■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

Page 9: Hack for Docker's Network

Q: Dockerはコンテナ間通信を制御出来るのか?

9

Page 10: Hack for Docker's Network

ドキュメントを確認してみると、制御機能、ありました。

10

Page 11: Hack for Docker's Network

ICC:Inter-ContainerCommunication

11

Page 12: Hack for Docker's Network

■ 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

Page 13: Hack for Docker's Network

■ 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

Page 14: Hack for Docker's Network

■ 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

Page 15: Hack for Docker's Network

-icc=true, -icc=falseiptablesルール差分、気になりました。

15

Page 16: Hack for Docker's Network

気になったので調べてみました。

16

Page 17: Hack for Docker's Network

ところで、-icc=true, -icc=falseを設定するには・・・

17

Page 18: Hack for Docker's Network

/etc/sysconfig/dockerを修正(RHEL6系の場合)

18

Page 19: Hack for Docker's Network

■ICC: /etc/sysconfig/docker

other_args="”

other_args="-icc=false”

default

falseの場合は、-icc=false $ sudo /etc/init.d/docker restart

設定反映の為、Daemonを再起動

19

Page 20: Hack for Docker's Network

-icc=true, -icc=falseルール比較する為の

シナリオ

20

Page 21: Hack for Docker's Network

■ルール比較のシナリオ

21

Page 22: Hack for Docker's Network

■ルール比較のシナリオ

$ sudo /etc/init.d/docker restarticcフラグを指定し、デーモンを再起動

-icc=?

22

Page 23: Hack for Docker's Network

■ルール比較のシナリオ

CT1

コンテナ(CT1)を作成

$ sudo docker run -d ¥-p 22 dhrp/sshd /usr/sbin/sshd -D

$ sudo /etc/init.d/docker restart

-icc=?

23

Page 24: Hack for Docker's Network

■ルール比較のシナリオ

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

Page 25: Hack for Docker's Network

■ルール比較のシナリオ

$ 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

Page 26: Hack for Docker's Network

■ルール比較のシナリオ

$ 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

Page 27: Hack for Docker's Network

■ルール比較のシナリオ

CT1 CT2

-icc=true

diff

rule rule

CT1 CT2

-icc=false

rule rule

ルールを比較

27

Page 28: Hack for Docker's Network

結果は・・・

28

Page 29: Hack for Docker's Network

■ルール比較結果

$ 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

Page 30: Hack for Docker's Network

コンテナ内の通信が遮断されてるか、確認してみる。

30

Page 31: Hack for Docker's Network

■コンテナ間通信遮断を確認

CT1 CT2

-icc=false

期待値は、パケットは行き来せず、

DROPされる事。31

Page 32: Hack for Docker's Network

■コンテナ間通信遮断を確認

CT1 CT2

-icc=false

sshコマンドを実行すると・・・

32

Page 33: Hack for Docker's Network

■コンテナ間通信遮断を確認

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

Page 34: Hack for Docker's Network

Q:sysctlは、どうなっている?

34

Page 35: Hack for Docker's Network

■コンテナ間通信遮断を確認

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

Page 36: Hack for Docker's Network

■コンテナ間通信遮断を確認

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

Page 37: Hack for Docker's Network

ICCをおさらい

37

Page 38: Hack for Docker's Network

■ 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

Page 39: Hack for Docker's Network

iccフラグにより、コンテナ間通信が

遮断される事は分かった。

39

Page 40: Hack for Docker's Network

しかし、

40

Page 41: Hack for Docker's Network

特定コンテナ間通信は、許可したい・・・

41

Page 42: Hack for Docker's Network

ドキュメントを確認してみると、要望を満たす機能を発見。

42

Page 43: Hack for Docker's Network

Link Containers

43

Page 44: Hack for Docker's Network

■ 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

Page 45: Hack for Docker's Network

この関係を図とコマンドにしてみると、

45

Page 46: Hack for Docker's Network

-icc=false

■ Link Containers

-icc=false 指定Dockerホスト

46

Page 47: Hack for Docker's Network

-icc=false

■ Link Containers

$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D

-name 指定でコンテナを作成。

47

Page 48: Hack for Docker's Network

-icc=false

CT01-name ct01

■ Link Containers

$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd ¥/usr/sbin/sshd -D

48

Page 49: Hack for Docker's Network

-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

Page 50: Hack for Docker's Network

-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

Page 51: Hack for Docker's Network

-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

Page 52: Hack for Docker's Network

-icc=false

CT02

CT01-name ct01

-link ct01:sshd

■ Link Containers

この関係はdocker psで確認出来る。

52

Page 53: Hack for Docker's Network

-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

Page 54: Hack for Docker's Network

検証をしてたら、nameの制約に遭遇。

54

Page 55: Hack for Docker's Network

-name <name>は、再利用不可能?

55

Page 56: Hack for Docker's Network

■ 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

Page 57: Hack for Docker's Network

■ 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

Page 58: Hack for Docker's Network

■ 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

Page 59: Hack for Docker's Network

今の所、-name <name>は、

ユニークにしておいた方が良い。

59

Page 60: Hack for Docker's Network

linkとnameの話に戻します。

60

Page 61: Hack for Docker's Network

-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

Page 62: Hack for Docker's Network

Q:この時のiptables ruleは、どうなっている?

62

Page 63: Hack for Docker's Network

■反映されてる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

Page 64: Hack for Docker's Network

■反映されてる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

Page 65: Hack for Docker's Network

■反映されてる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

Page 66: Hack for Docker's Network

■反映されてる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

Page 67: Hack for Docker's Network

Bugっぽいので、Issueを確認の上、

PRを送ってみようと思います。

67

Page 68: Hack for Docker's Network

Q:複雑なlink構成すると、どうなるのか?

68

Page 69: Hack for Docker's Network

-icc=false

■多段Link構成

CT12

CT01

CT21 CT22

CT11

-icc=false

CT02

CT01

3層構成へ 複数link

69

Page 70: Hack for Docker's Network

しかし、この複数link構成、仕様上不可能である事が判明する。

70

Page 71: Hack for Docker's Network

その仕様とは、linkフラグは文字列型である事。

71

Page 72: Hack for Docker's Network

■多段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

Page 73: Hack for Docker's Network

と言う事で、現仕様で構成可能なのは、

73

Page 74: Hack for Docker's Network

■多段Link構成

-icc=false

CT12

CT01

CT21 CT22

CT11

張れるlinkは1本のみ

74

Page 75: Hack for Docker's Network

多段link構成を作ってみる。

75

Page 76: Hack for Docker's Network

-icc=false

■多段Link構成

76

Page 77: Hack for Docker's Network

-icc=false

■多段Link構成

CT01

$ sudo docker run -d ¥-name ct01 ¥-p 22 dhrp/sshd /usr/sbin/sshd -D

77

Page 78: Hack for Docker's Network

-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

Page 79: Hack for Docker's Network

-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

Page 80: Hack for Docker's Network

-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

Page 81: Hack for Docker's Network

-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

Page 82: Hack for Docker's Network

Q:この時のiptables ruleは、どうなっている?

82

Page 83: Hack for Docker's Network

■反映されてる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

Page 84: Hack for Docker's Network

■反映されてる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

Page 85: Hack for Docker's Network

■ICC:まとめ

-icc=false

CT12

CT01

CT21 CT22

CT11

iccフラグでコンテナ間通信を制御可能

nameフラグでコンテナに名前付けが可能

パケットの制御はiptables

linkフラグで2点間通信許可が可能

85

Page 86: Hack for Docker's Network

Q:コンテナに狙ったIPアドレスを指定できないのか?

86

Page 87: Hack for Docker's Network

A:今のDockerには、割り当て機能が無い。

87

Page 88: Hack for Docker's Network

そこで登場するのが、

88

Page 89: Hack for Docker's Network

Pipework

89

Page 90: Hack for Docker's Network

■ Pipework

Software-Defined Networking for Linux Containers

Pipework lets you connect together containers in arbitrarily complex scenarios.

https://github.com/jpetazzo/pipework

多様なコンテナ間通信を提供

200行弱のシェルスクリプト

90

Page 91: Hack for Docker's Network

■ Pipework: Usage

$ pipework br1 $CTID 192.168.1.2/24

https://github.com/jpetazzo/pipework

使い方の1つ、コンテナに狙ったIPアドレスを

指定可能。

91

Page 92: Hack for Docker's Network

Pipeworkを動かしてみる。

92

Page 93: Hack for Docker's Network

■ Pipework

通常のコンテナ構成図。

CT

docker0

eth0veth0

93

Page 94: Hack for Docker's Network

■ Pipework

CT

docker0

eth0veth0

$ pipework br1 $CTID 192.168.1.2/24

Pipeworkを実行。

94

Page 95: Hack for Docker's Network

■ Pipework

CT

docker0

eth0veth0

$ pipework br1 $CTID 192.168.1.2/24

vethペアを作成。

eth1veth1

95

Page 96: Hack for Docker's Network

■ Pipework

CT

docker0

eth0veth0

br1

eth1veth1

vethをbr1に追加する。

$ pipework br1 $CTID 192.168.1.2/24

96

Page 97: Hack for Docker's Network

■ Pipework

CT

docker0

eth0veth0

br1

eth1veth1

eth1にIPアドレスを割り当て。

$ pipework br1 $CTID 192.168.1.2/24

97

Page 98: Hack for Docker's Network

■ Pipework

CT

docker0

eth0veth0

br1

eth1veth1

Pipeworkによって追加された新たなデバイス。

98

Page 99: Hack for Docker's Network

Pipeworkの他の機能は?

99

Page 100: Hack for Docker's Network

■ 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

Page 101: Hack for Docker's Network

■ Pipework + Open vSwitch

CT

docker0

eth0veth0

br1

eth1veth1

ここをOpen vSwitch化。

101

Page 102: Hack for Docker's Network

■ Pipework + Open vSwitch

CT

docker0

eth0veth0

ovsbr1

eth1veth1

$ pipework ovsbr1 $CTID 192.168.1.2/24

ovsbr1を指定するだけ。

102

Page 103: Hack for Docker's Network

ここまで重要なのは、PipeworkはDockerコマンドを一切実行してない事。

103

Page 104: Hack for Docker's Network

つまり、Pipeworkが対象にしているのは、

LXCコンテナである事。

104

Page 105: Hack for Docker's Network

PipeworkとDockerは、上手く住み分けされている。

105

Page 106: Hack for Docker's Network

以上、駆け足で進めて参りました・・・

106

Page 107: Hack for Docker's Network

■ Network周りを触ってみて・・・

107

・linkを始め、iptablse周りの実装がまだ枯れてなさそう⇒複数link等、EC2のSecurityGroups相当の機能が必要?

・複数Docker Host構成の場合・本体は、しばらく1ホストしか考慮に入れてなさそう?・ホスト超えした時のlinkは、どうするのか・複数ホスト管理、ネットワーク層管理・ホスト間通信、ホスト超えしたコンテナ間通信・Mesos, Marathon, Serf, Wakame-vdc, OpenVNet…

特にこの領域は、まだまだ発展途上。

Page 108: Hack for Docker's Network

ご清聴ありがとうございました

https://twitter.com/hansodehttp://blog.hansode.org/

108