Docker 从入门到实践 0.4默认情况下,容器可以主动访问到外部网络的连接,但是外部网络无法访问到容器。 容器所有到外部网络的连接,源地址都会被NAT成本地系统的IP地址。这是使用 iptables 的源地址伪装 操作实现的。 查看主机的 NAT 规则。 $ sudo iptables -t nat -nL ... Chain POSTROUTING (policy ACCEPT) target prot opt 容器允许外部访问,可以在 docker run 时候通过 -p 或 -P 参数来启用。 不管用那种办法,其实也是在本地的 iptable 的 nat 表中添加相应的规则。 使用 -P 时: $ iptables -t nat -nL ... Chain DOCKER (2 references) target prot opt source destination 0/0 0.0.0.0/0 tcp dpt:49153 to:172.17.0.2:80 使用 -p 80:80 时: $ iptables -t nat -nL Chain DOCKER (2 references) target prot opt source destination DNAT tcp0 码力 | 179 页 | 2.27 MB | 1 年前3
Docker 从入门到实践 0.9.0(2017-12-31)默认情况下,容器可以主动访问到外部网络的连接,但是外部网络无法访问到容器。 容器访问外部实现 容器所有到外部网络的连接,源地址都会被 NAT 成本地系统的 IP 地址。这是使用 iptables 的源地址伪装操作实现的。 查看主机的 NAT 规则。 $ sudo iptables -t nat -nL ... Chain POSTROUTING (policy ACCEPT) target prot 容器允许外部访问,可以在 docker run 时候通过 -p 或 -P 参数来启用。 不管用那种办法,其实也是在本地的 iptable 的 nat 表中添加相应的规则。 使用 -P 时: $ iptables -t nat -nL ... Chain DOCKER (2 references) target prot opt source 0.0.0/0 tcp dpt:49153 to:172.17. 0.2:80 使用 -p 80:80 时: 端口映射实现 148 $ iptables -t nat -nL Chain DOCKER (2 references) target prot opt source destination DNAT0 码力 | 370 页 | 6.73 MB | 1 年前3
共 2 条
- 1













