Docker コンテナからホスト OS (CoreOS,Windows)へのアクセス方法について
動作環境
以下の環境で検証しました
VirtualBox、Docker はインストール済みの前提で話を進めます
Windows10 Home Edition VirtualBox 5.1.6 docker 1.10.3 docker-machine 0.6.0
ブリッジインターフェースの確認
Docker のネットワークを管理している仮想ブリッジ "docker0" を確認します。
CoreOS 上で "ip a" と入力することで確認可能です。
$ ip a 7: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default link/ether 02:42:d4:14:51:45 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 scope global docker0 valid_lft forever preferred_lft forever
自分の環境では docker0 のアドレスは 172.17.0.1 でした
コンテナから CoreOS へのアクセス
コンテナから CoreOS へのアクセスは仮想ブリッジ "docker0" を通じて行うことが可能です
$ ping 172.17.0.1 PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data. 64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.784 ms 64 bytes from 172.17.0.1: icmp_seq=2 ttl=64 time=0.098 ms 64 bytes from 172.17.0.1: icmp_seq=3 ttl=64 time=0.086 ms 64 bytes from 172.17.0.1: icmp_seq=4 ttl=64 time=0.085 ms
コンテナから Windows へのアクセス
コンテナから Windows へのアクセスはデフォルトルートを通じて行うことが可能です
デフォルトルートは CoreOS 上で "ip r" と入力することで確認可能です
$ ip r default via 10.0.2.2 dev eth0 metric 1 10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 127.0.0.1 dev lo scope link 172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 172.18.0.0/16 dev br-5b890ae3c1a7 proto kernel scope link src 172.18.0.1 172.19.0.0/16 dev br-0fef2cb04591 proto kernel scope link src 172.19.0.1 192.168.99.0/24 dev eth1 proto kernel scope link src 192.168.99.100
自分の環境ではデフォルトルートのアドレスは 10.0.2.2 でした
$ ping 10.0.2.2 PING 10.0.2.2 (10.0.2.2) 56(84) bytes of data. 64 bytes from 10.0.2.2: icmp_seq=1 ttl=62 time=0.226 ms 64 bytes from 10.0.2.2: icmp_seq=2 ttl=62 time=0.466 ms 64 bytes from 10.0.2.2: icmp_seq=3 ttl=62 time=0.537 ms 64 bytes from 10.0.2.2: icmp_seq=4 ttl=62 time=0.435 ms
以上、コンテナから CoreOS、Windows 双方にアクセス可能なことが確認できました