系统集成Docker

docker宿主机器防火墙的问题

大家好,请问一个docker宿主机器防火墙的问题想确认一下运行docker容器的苏主机是否必须开启iptables,如下我的测试:[root@localhost ~]# /etc/init.d/iptables stopiptables:将链设置为政策 ACCEPT:filter               &...显示全部
大家好,请问一个docker宿主机器防火墙的问题
想确认一下运行docker容器的苏主机是否必须开启iptables,如下我的测试:
[root@localhost ~]# /etc/init.d/iptables stop
iptables:将链设置为政策 ACCEPT:filter                    [确定]
iptables:清除防火墙规则:                                 [确定]
iptables:正在卸载模块:                                   [确定]
[root@localhost ~]# /etc/init.d/iptables status
iptables:未运行防火墙。
[root@localhost ~]# /etc/init.d/docker restart
停止 docker:                                              [确定]
Starting docker:                                           [确定]
[root@localhost ~]# /etc/init.d/iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination
1    DOCKER     all  --  0.0.0.0/0            0.0.0.0/0
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           ctstate RELATED,ESTABLISHED
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination

Chain DOCKER (1 references)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  0.0.0.0/0            12.17.0.2           tcp dpt:80

表格:nat
Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination
1    DOCKER     all  --  0.0.0.0/0            0.0.0.0/0           ADDRTYPE match dst-type LOCAL

Chain POSTROUTING (policy ACCEPT)
num  target     prot opt source               destination
1    MASQUERADE  all  --  12.17.0.0/16         0.0.0.0/0
2    MASQUERADE  tcp  --  12.17.0.2            12.17.0.2           tcp dpt:80

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination
1    DOCKER     all  --  0.0.0.0/0           !127.0.0.0/8         ADDRTYPE match dst-type LOCAL

Chain DOCKER (2 references)
num  target     prot opt source               destination
1    DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:1016 to:12.17.0.2:80

[root@localhost ~]#收起
参与6

查看其它 4 个回答dl528888的回答

dl528888dl528888系统运维工程师游戏公司
hi,使用bridge进行创建容器的时候,如果默认docker里没有设置,会让docker额外对宿主机的iptables的nat链进行操作,如果你创建好docker容器后,在重启宿主机的iptables,那么你无法通过设置的端口连接容器。推荐关闭docker修改宿主机iptables功能,然后手动修改宿主机iptables的nat来控制防火墙功能。
互联网服务 · 2015-05-08
浏览11487

回答者

dl528888
系统运维工程师游戏公司
擅长领域: 云计算容器容器云

dl528888 最近回答过的问题

回答状态

  • 发布时间:2015-05-08
  • 关注会员:1 人
  • 回答浏览:11487
  • X社区推广