Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Docker基礎+docker0.9, 0.10概要

Docker基礎+docker0.9, 0.10概要

Kazuyuki Mori

April 11, 2014
Tweet

More Decks by Kazuyuki Mori

Other Decks in Programming

Transcript

  1. Who • @mainyaa • Kazuyuki Mori • フロントエンドからバックエンドまでやる系エンジニア • AngualrJSとDocker大好き

    • Topgate, Inc. - http://www.topgate.co.jp/ • Happy New World - http://d.hatena.ne.jp/mainyaa
  2. DockerのNetworking • 確認してみよう! • $ ip a • ifconfigとか使ってるのはおっさんらしいです ><

    • http://opcdiary.net/?p=28500 • RHEL7ではsystem-config-networkは廃止、 ifconfigやrouteなどのnet-toolsが非推奨
  3. $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue

    state UNKNOWN group default 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP group default qlen 1000 link/ether 42:01:0a:f0:63:2d brd ff:ff:ff:ff:ff:ff inet 10.240.99.45/32 brd 10.240.99.45 scope global eth0 valid_lft forever preferred_lft forever 3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default link/ether 9e:7a:ac:ed:32:30 brd ff:ff:ff:ff:ff:ff inet 172.17.42.1/16 scope global docker0 valid_lft forever preferred_lft forever
  4. $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue

    state UNKNOWN group default 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP group default qlen 1000 link/ether 42:01:0a:f0:63:2d brd ff:ff:ff:ff:ff:ff inet 10.240.99.45/32 brd 10.240.99.45 scope global eth0 valid_lft forever preferred_lft forever 3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default link/ether 9e:7a:ac:ed:32:30 brd ff:ff:ff:ff:ff:ff inet 172.17.42.1/16 scope global docker0 valid_lft forever preferred_lft forever
  5. $ sudo docker run base ip a ... 18: eth0:

    <NO-CARRIER,BROADCAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state DOWN qlen 1000 link/ether ca:2b:5e:2e:ce:78 brd ff:ff:ff:ff:ff:ff inet 172.17.0.9/16 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::c82b:5eff:fe2e:ce78/64 scope link tentative valid_lft forever preferred_lft forever
  6. $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue

    state UNKNOWN group default 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP group default qlen 1000 link/ether 42:01:0a:f0:eb:dd brd ff:ff:ff:ff:ff:ff inet 10.240.235.221/32 brd 10.240.235.221 scope global eth0 valid_lft forever preferred_lft forever 3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc noqueue state UP group default link/ether 56:84:7a:fe:97:99 brd ff:ff:ff:ff:ff:ff inet 172.17.42.1/16 scope global docker0 valid_lft forever preferred_lft forever 23: vethd07b: <BROADCAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast master docker0 state UP group default qlen 1000 link/ether 52:4f:9d:fe:a0:72 brd ff:ff:ff:ff:ff:ff 25: veth572b: <BROADCAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast master docker0 state UP group default qlen 1000 link/ether a2:0d:00:82:ef:fa brd ff:ff:ff:ff:ff:ff 29: vethad91: <BROADCAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast master docker0 state UP group default qlen 1000 link/ether 82:a9:af:0d:73:a2 brd ff:ff:ff:ff:ff:ff
  7. Ubuntu Docker eth0 172.17.0.1 eth0 docker0 vethd07b 172.17.0.2 eth0 veth572b

    10.240.99.45 172.17.0.0/16 -icc=[true|false] docker run --link refs: http://deeeet.com/writing/2014/05/11/docker-network/ IPマスカレード
  8. $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue

    state UNKNOWN group default 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP group default qlen 1000 link/ether 42:01:0a:f0:eb:dd brd ff:ff:ff:ff:ff:ff inet 10.240.235.221/32 brd 10.240.235.221 scope global eth0 valid_lft forever preferred_lft forever 3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc noqueue state UP group default link/ether 56:84:7a:fe:97:99 brd ff:ff:ff:ff:ff:ff inet 172.17.42.1/16 scope global docker0 valid_lft forever preferred_lft forever 23: vethd07b: <BROADCAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast master docker0 state UP group default qlen 1000 link/ether 52:4f:9d:fe:a0:72 brd ff:ff:ff:ff:ff:ff 25: veth572b: <BROADCAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast master docker0 state UP group default qlen 1000 link/ether a2:0d:00:82:ef:fa brd ff:ff:ff:ff:ff:ff
  9. $ sudo docker run --link redis1:redis1 base env HOME=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

    HOSTNAME=92b3a500b0ef TERM=xterm REDIS1_PORT=tcp://172.17.0.2:6379 REDIS1_PORT_6379_TCP=tcp://172.17.0.2:6379 REDIS1_PORT_6379_TCP_ADDR=172.17.0.2 REDIS1_PORT_6379_TCP_PORT=6379 REDIS1_PORT_6379_TCP_PROTO=tcp REDIS1_NAME=/happy_colden/redis1
  10. $ sudo docker run --link redis1:redis1 base cat /etc/hosts 172.17.0.4

    950990b968c2 127.0.0.1 localhost ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 172.17.0.2 redis1
  11. -link • 良い: ◦ 手軽で便利。安全。Dockerが勝手にポートを振り分けて くれる • 悪い: ◦ $

    sudo docker inspect --format ' {{ .NetworkSettings.IPAddress }} ' <container id> ◦ スケールしない ◦ 異なるホストにはlinkできない
  12. $ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue

    state UNKNOWN group default 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 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP group default qlen 1000 link/ether 42:01:0a:f0:eb:dd brd ff:ff:ff:ff:ff:ff inet 10.240.235.221/32 brd 10.240.235.221 scope global eth0 valid_lft forever preferred_lft forever 3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc noqueue state UP group default link/ether 56:84:7a:fe:97:99 brd ff:ff:ff:ff:ff:ff inet 172.17.42.1/16 scope global docker0 valid_lft forever preferred_lft forever
  13. $ sudo docker run --net=host base ip a 2: eth0:

    <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP qlen 1000 link/ether 42:01:0a:f0:eb:dd brd ff:ff:ff:ff:ff:ff inet 10.240.235.221/32 brd 10.240.235.221 scope global eth0 valid_lft forever preferred_lft forever 3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1460 qdisc noqueue state DOWN link/ether 56:84:7a:fe:97:99 brd ff:ff:ff:ff:ff:ff inet 172.17.42.1/16 scope global docker0 valid_lft forever preferred_lft forever
  14. Open vSwitch • オープンソースの仮想スイッチ • 柔軟なネットワークが可能になる ◦ 転送機能: Bridge, VLAN,

    STP, LACP, GRE, GRE over IPsec, CAPWAP ◦ 管理機能: NetFlow, sFlow ◦ 制御機能: OpenFlow 1.0,1.1,1.2 • sudo apt-get install openvswitch-controller openvswitch-switch openvswitch-datapath-source refs: http://www.slideshare.net/kotto_hihihi/openv-switch
  15. Docker + Open vSwitch • Dockerデーモンのオプションに-b=noneを指定する • 全てのコンテナをdocker0ブリッジを経由する • docker0ブリッジはOpen

    vSwitchから作られたbr0ブリッジ に接続される • GRE Tunnelで異なるホスト間のブリッジを接続し、バーチャ ルなネットワーク空間172.16.42.2/24を構築する • refs: http://goldmann.pl/blog/2014/01/21/connecting-docker-containers-on-multiple-hosts/
  16. Open vSwitch Open vSwitch Docker eth0 172.16.4 2.21 eth0 docker0

    172.16.4 2.14 eth0 refs: http://goldmann.pl/blog/2014/01/21/connecting-docker-containers-on-multiple-hosts/ Docker eth0 172.16.4 2.13 eth0 docker0 172.16.4 2.15 eth0 host2 host1 br0 gre0 br0 gre0 GRE tunnel
  17. Docker + Open vSwitch • 良い点: ◦ 安全。ポータビリティも保ちつつ多数のホストに展開でき る •

    悪い点: ◦ IPが被ってしまうおそれがあるため、 goldmann/docker-dhcp などの、DHCPを使う refs: http://d.hatena.ne.jp/xlis/20130317/1363507787