登录

docker 运行的时候映射了主机端口,在iptables里面还需要开放吗?

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            multiport dports 500,4500,1701
ACCEPT     esp  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:500
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:500
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:4500
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:1701
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:1723

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
DOCKER-ISOLATION  all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
DOCKER     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
DOCKER     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
ACCEPT     all  --  192.168.18.0/24      0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
ACCEPT     all  --  10.31.0.0/24         0.0.0.0/0           
ACCEPT     all  --  10.31.1.0/24         0.0.0.0/0           
ACCEPT     all  --  10.31.2.0/24         0.0.0.0/0           

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain DOCKER (2 references)
target     prot opt source               destination         
ACCEPT     udp  --  0.0.0.0/0            172.17.0.2           udp dpt:4500
ACCEPT     udp  --  0.0.0.0/0            172.17.0.2           udp dpt:500
ACCEPT     tcp  --  0.0.0.0/0            172.17.0.3           tcp dpt:80
ACCEPT     tcp  --  0.0.0.0/0            172.17.0.5           tcp dpt:443
ACCEPT     tcp  --  0.0.0.0/0            172.17.0.5           tcp dpt:80
ACCEPT     tcp  --  0.0.0.0/0            172.17.0.7           tcp dpt:9001
ACCEPT     tcp  --  0.0.0.0/0            172.18.0.2           tcp dpt:993
ACCEPT     tcp  --  0.0.0.0/0            172.18.0.2           tcp dpt:587
ACCEPT     tcp  --  0.0.0.0/0            172.18.0.2           tcp dpt:143
ACCEPT     tcp  --  0.0.0.0/0            172.18.0.2           tcp dpt:25

Chain DOCKER-ISOLATION (1 references)
target     prot opt source               destination         
DROP       all  --  0.0.0.0/0            0.0.0.0/0           
DROP       all  --  0.0.0.0/0            0.0.0.0/0           
RETURN     all  --  0.0.0.0/0            0.0.0.0/0

我下面那些25,143,587那些应该是docker自动添加的,我还需要开放主机的对应端口才能访问吗?

# Docker
女神的闺蜜爱上我 女神的闺蜜爱上我 2481 天前 1534 次浏览

全部回复(1) 我要回复

  • 学习ing

    学习ing2017-07-05 10:48:55

    要看你 docker 的网络模式 ,

    1. 如果是 bridge 模式,端口映射规则为 ip:port:targetPort,

      1. 举例来说 0.0.0.0:80:8080,这种情况表示 宿主机的 80 端口 与 容器的 8080 端口做了映射关系,并且没有对 IP 做限制,这时任何对该宿主机的 80 端口请求都会转发到容器内的 8080 端口上,无需额外的 iptables 设置。(即使防火墙事先没有开放 80 端口,也是可行的。因为端口映射会自己修改 iptables 规则)。

      2. 如果有明确指定 IP 地址,则 iptables 规则会限定,仅通过该 IP 的 80 端口,才能访问到容器内的 8080 端口。docker 端口映射实际就是通过修改 iptables 规则来实现的网络互通。

    2. 如果是 net 模式,那和你在宿主机上起一个端口监听是一样的,不会有额外的 iptables 规则的变动,这时需要手动设置 iptables 允许外部访问;

    回复
    0
  • 取消 回复 发送