-p 50000:50000
だけしているコンテナがある場合
- 外部からの接続用設定の確認(iptables)
root@lubuntu:~# iptables -t nat -L PREROUTING -nv
Chain PREROUTING (policy ACCEPT 23 packets, 3088 bytes)
pkts bytes target prot opt in out source destination
0 0 DOCKER all -- * * 0.0.0.0/0 0.0.0.0/0 ADDRTYPE match dst-type LOCAL
root@lubuntu:~# iptables -t nat -L OUTPUT -nv
Chain OUTPUT (policy ACCEPT 47 packets, 8521 bytes)
pkts bytes target prot opt in out source destination
0 0 DOCKER all -- * * 0.0.0.0/0 !127.0.0.0/8 ADDRTYPE match dst-type LOCAL
root@lubuntu:~# iptables -t nat -L DOCKER -nv
Chain DOCKER (2 references)
pkts bytes target prot opt in out source destination
0 0 DNAT tcp -- !docker0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:50000 to:172.17.0.2:50000
bridge インターフェース docker0 "以外から"( =eth0 など) から 0.0.0.0:50000
に来たアクセスを 172.17.0.2:50000
へ送る。
- docker-proxy の確認
root@lubuntu:~# ps aux | grep [d]ocker-proxy
root 25979 0.0 0.3 234652 13384 ? Sl 18:10 0:00 docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 50000 -container-ip 172.17.0.2 -container-port 50000
- masguerade の確認(コンテナから外部接続用)
root@lubuntu:~# iptables -t nat -L POSTROUTING -nv
Chain POSTROUTING (policy ACCEPT 24 packets, 2999 bytes)
pkts bytes target prot opt in out source destination
2 327 MASQUERADE all -- * docker0 0.0.0.0/0 0.0.0.0/0 ADDRTYPE match src-type LOCAL
4 160 MASQUERADE all -- * !docker0 172.17.0.0/16 0.0.0.0/0
0 0 MASQUERADE tcp -- * * 172.17.0.2 172.17.0.2 tcp dpt:50000
- 1行目がホストから bridge に繋がっている docker コンテナ宛は masquerade する設定
- 設定上利用されているがなぜ必要なのだろうか。
- 2行目は
172.17.0.0/16
(=この場合 bridge に繋がっているコンテナ全て)から bridge 以外へのアクセスを masquerade する設定- コンテナからインターネットやホストなどに接続するとき利用される
- 3行目はコンテナ自身の折り返しの通信用。
--userland-proxy=true
の時は使われないはず- なぜ入っているか不明。
iptables を確認する場合は iptables-save
コマンドを使うほうが見落とが少なくわかりやすいが、説明をわかりやすくするためここでは iptalbes
コマンドをそのまま利用している。