はじめに
最近業務でDockerを触る機会があります。これまで研修などで触れることはありましたが、やはり業務となるとわからなくなることがとても多くあります。その中でもつい最近わからなかったのが、Dockerを導入するホストに複数NICがついている場合、コンテナからの通信はどのようになるのかでした。こちらは色々と調べてみたのですが明確な回答にたどり着けなかったため、ひとまずは触って確かめてみようと思い、検証いたしました。
Dockerのネットワークの基本
Dockerのネットワークは、デフォルトではbridgeを利用したネットワークになります。bridgeはDockerを起動した時点で自動的に作成され、bridgeとコンテナNICとの接続は、仮想NIC(virtual ethernet)によって実現します。
コンテナからホストのネットワークへの通信は、ホストのiptablesによるIPマスカレードを利用します。コンテナネットワークからの通信を許可し、コンテナからの通信をホストのNICのIPアドレスにNAT変換することで、ホスト外部との通信も可能にします。
検証
ここから検証内容の紹介になります。
検証内容
今回は以下のような状況を想定しています。
- ホストは2つのNICを備える
- 1つはインターネットへの通信用
- もう一つはホストのネットワーク内部の別ホストとの通信用
上記をまとめた図が以下になります。
検証環境
最近業務でAzureに触れる機会が多いため、今回の検証でもAzureを利用しました。Azureで構築する仮想マシンには、別のサブネットに属する2つのネットワークインターフェイスを付与します。
- 仮想ネットワーク
- テスト用VNet (10.1.0.0/16)
- 東日本リージョン
- サブネット
- default (10.1.0.0/24)
- テスト用サブネット (10.1.1.0/24)
- 仮想マシン
- CentOS7.5
- Docker (yum installで導入)
- 1.13.1
設定内容の確認
検証を行う前に、事前に設定等を確認しておきます。なお設定はdockerのインストール・起動を完了したのちの状態で確認しています。
コンテナ起動前
ip -d a
[root@centos-docker03 ~]# ip -d a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0d:3a:51:82:88 brd ff:ff:ff:ff:ff:ff promiscuity 0 numtxqueues 64 numrxqueues 64 gso_max_size 62780 gso_max_segs 65535 inet 10.1.0.8/24 brd 10.1.0.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20d:3aff:fe51:8288/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0d:3a:50:4c:d3 brd ff:ff:ff:ff:ff:ff promiscuity 0 numtxqueues 64 numrxqueues 64 gso_max_size 62780 gso_max_segs 65535 inet 10.1.1.4/24 brd 10.1.1.255 scope global noprefixroute eth1 valid_lft forever preferred_lft forever inet6 fe80::c8d8:b4c1:ce57:9918/64 scope link noprefixroute valid_lft forever preferred_lft forever ★Docker起動により作成される (Link Down状態) 4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:4e:89:9b:b9 brd ff:ff:ff:ff:ff:ff promiscuity 0 bridge forward_delay 1500 hello_time 200 max_age 2000 ageing_time 30000 stp_state 0 priority 32768 vlan_filtering 0 vlan_protocol 802.1Q bridge_id 8000.2:42:4e:89:9b:b9 designated_root 8000.2:42:4e:89:9b:b9 root_port 0 root_path_cost 0 topology_change 0 topology_change_detected 0 hello_timer 0.00 tcn_timer 0.00 topology_change_timer 0.00 gc_timer 270.55 vlan_default_pvid 1 vlan_stats_enabled 0 group_fwd_mask 0 group_address 01:80:c2:00:00:00 mcast_snooping 1 mcast_router 1 mcast_query_use_ifaddr 0 mcast_querier 0 mcast_hash_elasticity 4 mcast_hash_max 512 mcast_last_member_count 2 mcast_startup_query_count 2 mcast_last_member_interval 100 mcast_membership_interval 26000 mcast_querier_interval 25500 mcast_query_interval 12500 mcast_query_response_interval 1000 mcast_startup_query_interval 3125 mcast_stats_enabled 0 mcast_igmp_version 2 mcast_mld_version 1 nf_call_iptables 0 nf_call_ip6tables 0 nf_call_arptables 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 inet 172.17.0.1/16 scope global docker0 valid_lft forever preferred_lft forever
ip r
[root@centos-docker03 ~]# ip r default via 10.1.0.1 dev eth0 10.1.0.0/24 dev eth0 proto kernel scope link src 10.1.0.8 10.1.1.0/24 dev eth1 proto kernel scope link src 10.1.1.4 metric 100 168.63.129.16 via 10.1.0.1 dev eth0 proto static 169.254.0.0/16 dev eth0 scope link metric 1002 169.254.169.254 via 10.1.0.1 dev eth0 proto static ★Docker起動により作成される 172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
brctl show
Docker起動によりブリッジが作成されます。
[root@centos-docker03 ~]# brctl show bridge name bridge id STP enabled interfaces docker0 8000.02424e899bb9 no
iptables
[root@centos-docker03 ~]# iptables -L -v Chain INPUT (policy ACCEPT 475 packets, 124K bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source destination ★Docker起動により作成される 0 0 DOCKER-ISOLATION all -- any any anywhere anywhere ★Docker起動により作成される 0 0 DOCKER all -- any docker0 anywhere anywhere 0 0 ACCEPT all -- any docker0 anywhere anywhere ctstate RELATED,ESTABLISHED 0 0 ACCEPT all -- docker0 !docker0 anywhere anywhere 0 0 ACCEPT all -- docker0 docker0 anywhere anywhere Chain OUTPUT (policy ACCEPT 504 packets, 103K bytes) pkts bytes target prot opt in out source destination ★Docker起動により作成される Chain DOCKER (1 references) pkts bytes target prot opt in out source destination ★Docker起動により作成される Chain DOCKER-ISOLATION (1 references) pkts bytes target prot opt in out source destination 0 0 RETURN all -- any any anywhere anywhere
[root@centos-docker03 ~]# iptables -L -t nat Chain PREROUTING (policy ACCEPT) target prot opt source destination ★Docker起動により作成される DOCKER all -- anywhere anywhere ADDRTYPE match dst-type LOCAL Chain INPUT (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination ★Docker起動により作成される DOCKER all -- anywhere !loopback/8 ADDRTYPE match dst-type LOCAL Chain POSTROUTING (policy ACCEPT) target prot opt source destination ★Docker起動により作成される MASQUERADE all -- 172.17.0.0/16 anywhere ★Docker起動により作成される Chain DOCKER (2 references) target prot opt source destination RETURN all -- anywhere anywhere
[root@centos-docker03 ~]# iptables -L -t filter Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy DROP) target prot opt source destination ★Docker起動により作成される DOCKER-ISOLATION all -- anywhere anywhere ★Docker起動により作成される DOCKER all -- anywhere anywhere ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere Chain OUTPUT (policy ACCEPT) target prot opt source destination ★Docker起動により作成される Chain DOCKER (1 references) target prot opt source destination ★Docker起動により作成される Chain DOCKER-ISOLATION (1 references) target prot opt source destination RETURN all -- anywhere anywhere
コンテナ起動後
以下のようにコンテナを起動します(コマンドはこちらの記事を参照しました。)
[root@centos-docker03 ~]# docker run -d -p 5000:5000 --restart=always --name registry registry:2 Unable to find image 'registry:2' locally Trying to pull repository docker.io/library/registry ... 2: Pulling from docker.io/library/registry c87736221ed0: Pull complete 1cc8e0bb44df: Pull complete 54d33bcb37f5: Pull complete e8afc091c171: Pull complete b4541f6d3db6: Pull complete Digest: sha256:8004747f1e8cd820a148fb7499d71a76d45ff66bac6a29129bfdbfdc0154d146 Status: Downloaded newer image for docker.io/registry:2 89c48419d0ef310a6c9f49325ee6b72afdc9d4f00ae1dd39c5a923a4fbb78561 [root@centos-docker03 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 89c48419d0ef registry:2 "/entrypoint.sh /e..." 11 seconds ago Up 10 seconds 0.0.0.0:5000->5000/tcp registry
ip -d a
[root@centos-docker03 ~]# ip -d a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0d:3a:51:82:88 brd ff:ff:ff:ff:ff:ff promiscuity 0 numtxqueues 64 numrxqueues 64 gso_max_size 62780 gso_max_segs 65535 inet 10.1.0.8/24 brd 10.1.0.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20d:3aff:fe51:8288/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:0d:3a:50:4c:d3 brd ff:ff:ff:ff:ff:ff promiscuity 0 numtxqueues 64 numrxqueues 64 gso_max_size 62780 gso_max_segs 65535 inet 10.1.1.4/24 brd 10.1.1.255 scope global noprefixroute eth1 valid_lft forever preferred_lft forever inet6 fe80::c8d8:b4c1:ce57:9918/64 scope link noprefixroute valid_lft forever preferred_lft forever ★コンテナ起動によりLink UP状態になる 4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default link/ether 02:42:4e:89:9b:b9 brd ff:ff:ff:ff:ff:ff promiscuity 0 bridge forward_delay 1500 hello_time 200 max_age 2000 ageing_time 30000 stp_state 0 priority 32768 vlan_filtering 0 vlan_protocol 802.1Q bridge_id 8000.2:42:4e:89:9b:b9 designated_root 8000.2:42:4e:89:9b:b9 root_port 0 root_path_cost 0 topology_change 0 topology_change_detected 0 hello_timer 0.00 tcn_timer 0.00 topology_change_timer 0.00 gc_timer 206.25 vlan_default_pvid 1 vlan_stats_enabled 0 group_fwd_mask 0 group_address 01:80:c2:00:00:00 mcast_snooping 1 mcast_router 1 mcast_query_use_ifaddr 0 mcast_querier 0 mcast_hash_elasticity 4 mcast_hash_max 512 mcast_last_member_count 2 mcast_startup_query_count 2 mcast_last_member_interval 100 mcast_membership_interval 26000 mcast_querier_interval 25500 mcast_query_interval 12500 mcast_query_response_interval 1000 mcast_startup_query_interval 3125 mcast_stats_enabled 0 mcast_igmp_version 2 mcast_mld_version 1 nf_call_iptables 0 nf_call_ip6tables 0 nf_call_arptables 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 inet 172.17.0.1/16 scope global docker0 valid_lft forever preferred_lft forever inet6 fe80::42:4eff:fe89:9bb9/64 scope link valid_lft forever preferred_lft forever ★コンテナ起動により作成される 6: veth2aa8462@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default link/ether 52:a2:ce:7f:f6:6b brd ff:ff:ff:ff:ff:ff link-netnsid 0 promiscuity 1 veth bridge_slave state forwarding priority 32 cost 2 hairpin off guard off root_block off fastleave off learning on flood on port_id 0x8001 port_no 0x1 designated_port 32769 designated_cost 0 designated_bridge 8000.2:42:4e:89:9b:b9 designated_root 8000.2:42:4e:89:9b:b9 hold_timer 0.00 message_age_timer 0.00 forward_delay_timer 0.00 topology_change_ack 0 config_pending 0 proxy_arp off proxy_arp_wifi off mcast_router 1 mcast_fast_leave off mcast_flood on numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 inet6 fe80::50a2:ceff:fe7f:f66b/64 scope link valid_lft forever preferred_lft forever
ip r
[root@centos-docker03 ~]# ip r default via 10.1.0.1 dev eth0 10.1.0.0/24 dev eth0 proto kernel scope link src 10.1.0.8 10.1.1.0/24 dev eth1 proto kernel scope link src 10.1.1.4 metric 100 168.63.129.16 via 10.1.0.1 dev eth0 proto static 169.254.0.0/16 dev eth0 scope link metric 1002 169.254.169.254 via 10.1.0.1 dev eth0 proto static 172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
brctl show
コンテナ起動により作成されるvethとdockerブリッジが紐づけられます。
[root@centos-docker03 ~]# brctl show bridge name bridge id STP enabled interfaces docker0 8000.02424e899bb9 no veth2aa8462
iptables
[root@centos-docker03 ~]# iptables -L -v Chain INPUT (policy ACCEPT 478 packets, 116K bytes) pkts bytes target prot opt in out source destination Chain FORWARD (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 DOCKER-ISOLATION all -- any any anywhere anywhere 0 0 DOCKER all -- any docker0 anywhere anywhere 0 0 ACCEPT all -- any docker0 anywhere anywhere ctstate RELATED,ESTABLISHED 0 0 ACCEPT all -- docker0 !docker0 anywhere anywhere 0 0 ACCEPT all -- docker0 docker0 anywhere anywhere Chain OUTPUT (policy ACCEPT 484 packets, 96633 bytes) pkts bytes target prot opt in out source destination Chain DOCKER (1 references) pkts bytes target prot opt in out source destination ★コンテナ起動により設定される 0 0 ACCEPT tcp -- !docker0 docker0 anywhere 172.17.0.2 tcp dpt:commplex-main Chain DOCKER-ISOLATION (1 references) pkts bytes target prot opt in out source destination 0 0 RETURN all -- any any anywhere anywhere [root@centos-docker03 ~]#
[root@centos-docker03 ~]# iptables -L -t nat Chain PREROUTING (policy ACCEPT) target prot opt source destination DOCKER all -- anywhere anywhere ADDRTYPE match dst-type LOCAL Chain INPUT (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination DOCKER all -- anywhere !loopback/8 ADDRTYPE match dst-type LOCAL Chain POSTROUTING (policy ACCEPT) target prot opt source destination MASQUERADE all -- 172.17.0.0/16 anywhere ★コンテナ起動により設定される MASQUERADE tcp -- 172.17.0.2 172.17.0.2 tcp dpt:commplex-main Chain DOCKER (2 references) target prot opt source destination RETURN all -- anywhere anywhere ★コンテナ起動により設定される DNAT tcp -- anywhere anywhere tcp dpt:commplex-main to:172.17.0.2:5000
[root@centos-docker03 ~]# iptables -L -t filter Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy DROP) target prot opt source destination DOCKER-ISOLATION all -- anywhere anywhere DOCKER all -- anywhere anywhere ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere Chain OUTPUT (policy ACCEPT) target prot opt source destination Chain DOCKER (1 references) target prot opt source destination ★コンテナ起動により設定される ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:commplex-main Chain DOCKER-ISOLATION (1 references) target prot opt source destination RETURN all -- anywhere anywhere
コンテナ内部のIPアドレス
[root@centos-docker03 ~]# docker exec -it registry ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000 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 inet6 ::1/128 scope host valid_lft forever preferred_lft forever 5: eth0@if6: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff inet 172.17.0.2/16 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::42:acff:fe11:2/64 scope link valid_lft forever preferred_lft forever [root@centos-docker03 ~]#
検証1. コンテナからホストNIC宛にPing疎通を確認
まずはコンテナからホスト1のNIC宛にping疎通が可能かどうか確認します。その結果、それぞれのNICに対してping疎通が確認できました。
■コンテナ内部からホスト1のeth0に向けてping [root@centos-docker03 ~]# docker exec -it registry ping 10.1.0.8 PING 10.1.0.8 (10.1.0.8): 56 data bytes 64 bytes from 10.1.0.8: seq=0 ttl=64 time=0.163 ms 64 bytes from 10.1.0.8: seq=1 ttl=64 time=0.129 ms 64 bytes from 10.1.0.8: seq=2 ttl=64 time=0.088 ms ^C --- 10.1.0.8 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 0.088/0.126/0.163 ms ■コンテナ内部からホスト1のeth1に向けてping★ [root@centos-docker03 ~]# docker exec -it registry ping 10.1.1.4 PING 10.1.1.4 (10.1.1.4): 56 data bytes 64 bytes from 10.1.1.4: seq=0 ttl=64 time=0.120 ms 64 bytes from 10.1.1.4: seq=1 ttl=64 time=0.126 ms 64 bytes from 10.1.1.4: seq=2 ttl=64 time=0.113 ms ^C --- 10.1.1.4 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 0.113/0.119/0.126 ms
なお、Azureの仮想ネットワークは、デフォルトではサブネット間ルーティングが有効となります。そのため、ホスト1のeth0から迂回してeth1へと通信される可能性はないか、と考えました。そこで念のため、TestSubnetにネットワークセキュリティグループを設定し、defaultサブネットからの通信は拒否するよう設定し、同様の検証を行いましたが、やはりeth1への通信は可能でした。
検証2. コンテナ内部からインターネット向けにping
次にコンテナ内部からインターネット (ここでは8.8.8.8)に疎通性があるかを確認します。また、ホスト上のNICでtcpdumpを行い、どのNICを通して通信が行われるかを確認します。
■コンテナ内部からインターネット向けにping [root@centos-docker03 ~]# docker exec -it registry ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8): 56 data bytes 64 bytes from 8.8.8.8: seq=0 ttl=52 time=1.773 ms 64 bytes from 8.8.8.8: seq=1 ttl=52 time=1.819 ms 64 bytes from 8.8.8.8: seq=2 ttl=52 time=1.921 ms 64 bytes from 8.8.8.8: seq=3 ttl=52 time=1.851 ms ■上記コマンド実行時にホストのeth0でtcpdump [root@centos-docker03 ~]# tcpdump -e -s 0 -nn -i eth0 not port 22 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes 13:49:30.514417 00:0d:3a:51:82:88 > 12:34:56:78:9a:bc, ethertype IPv4 (0x0800), length 98: 10.1.0.8 > 8.8.8.8: ICMP echo request, id 3072, seq 39, length 64 13:49:30.516052 12:34:56:78:9a:bc > 00:0d:3a:51:82:88, ethertype IPv4 (0x0800), length 98: 8.8.8.8 > 10.1.0.8: ICMP echo reply, id 3072, seq 39, length 64 13:49:31.514606 00:0d:3a:51:82:88 > 12:34:56:78:9a:bc, ethertype IPv4 (0x0800), length 98: 10.1.0.8 > 8.8.8.8: ICMP echo request, id 3072, seq 40, length 64 13:49:31.516308 12:34:56:78:9a:bc > 00:0d:3a:51:82:88, ethertype IPv4 (0x0800), length 98: 8.8.8.8 > 10.1.0.8: ICMP echo reply, id 3072, seq 40, length 64 13:49:32.514735 00:0d:3a:51:82:88 > 12:34:56:78:9a:bc, ethertype IPv4 (0x0800), length 98: 10.1.0.8 > 8.8.8.8: ICMP echo request, id 3072, seq 41, length 64 13:49:32.516457 12:34:56:78:9a:bc > 00:0d:3a:51:82:88, ethertype IPv4 (0x0800), length 98: 8.8.8.8 > 10.1.0.8: ICMP echo reply, id 3072, seq 41, length 64 ■上記コマンド実行時にホストのeth1でtcpdump [root@centos-docker03 ~]# tcpdump -e -s 0 -nn -i eth1 not port 22 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes ^C 0 packets captured 0 packets received by filter 0 packets dropped by kernel
検証3. コンテナから別ホスト宛にPing疎通を確認
次にホスト1のコンテナから別のホスト2のNICに対してping疎通性があるかどうか確認しました。なおホスト2の宛先となるNICはTestSubnetサブネットに属します。
■コンテナ内部からホスト2のeth0に向けてping [root@centos-docker03 ~]# docker exec -it registry ping 10.1.1.5 PING 10.1.1.5 (10.1.1.5): 56 data bytes 64 bytes from 10.1.1.5: seq=0 ttl=63 time=0.880 ms 64 bytes from 10.1.1.5: seq=1 ttl=63 time=0.918 ms 64 bytes from 10.1.1.5: seq=2 ttl=63 time=0.815 ms ^C --- 10.1.1.5 ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max = 0.815/0.871/0.918 ms [root@centos-docker03 ~]# ■上記コマンド実行時にホスト1のeth1でtcpdump [root@centos-docker03 ~]# tcpdump -e -s 0 -nn -i eth1 not port 22 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes 08:55:15.581960 00:0d:3a:50:4c:d3 > 12:34:56:78:9a:bc, ethertype IPv4 (0x0800), length 98: 10.1.1.4 > 10.1.1.5: ICMP echo request, id 40960, seq 42, length 64 08:55:15.582687 74:83:ef:a9:40:a1 > 00:0d:3a:50:4c:d3, ethertype IPv4 (0x0800), length 98: 10.1.1.5 > 10.1.1.4: ICMP echo reply, id 40960, seq 42, length 64 08:55:16.582120 00:0d:3a:50:4c:d3 > 12:34:56:78:9a:bc, ethertype IPv4 (0x0800), length 98: 10.1.1.4 > 10.1.1.5: ICMP echo request, id 40960, seq 43, length 64 08:55:16.582872 74:83:ef:a9:40:a1 > 00:0d:3a:50:4c:d3, ethertype IPv4 (0x0800), length 98: 10.1.1.5 > 10.1.1.4: ICMP echo reply, id 40960, seq 43, length 64 08:55:17.582242 00:0d:3a:50:4c:d3 > 12:34:56:78:9a:bc, ethertype IPv4 (0x0800), length 98: 10.1.1.4 > 10.1.1.5: ICMP echo request, id 40960, seq 44, length 64 08:55:17.583183 74:83:ef:a9:40:a1 > 00:0d:3a:50:4c:d3, ethertype IPv4 (0x0800), length 98: 10.1.1.5 > 10.1.1.4: ICMP echo reply, id 40960, seq 44, length 64 ^C 6 packets captured 6 packets received by filter 0 packets dropped by kernel
まとめ
今回はホストに複数NICが付与された状態でのDockerのネットワークの動きについて簡単な検証を行いました。その結果、複数NICが付与された状態でも、それぞれのNICを通した通信は可能であるように見えます。
今回検証した目的は一応確認できましたが、バックグラウンドのロジックを十分理解できてなく、また検証の際の確認事項等に抜け漏れがあるかもしれません。間違いやご指摘等ございましたらコメントいただければ幸いです。
参考文献
Dockerコンテナに複数のNICを付与する方法 (CentOS 7)
Routing from docker containers using a different physical network interface and default gateway