其实应该说是docker和这两者之间的恩怨情仇
为什么这么说?因为每当docker服务在启动的时候,都会根据自己的网络情况(如docker0网桥)、容器地址分配情况自动配置iptables规则,本来这很正常,规则有序。
不巧的是centos7中冒出来一个firewalld,这就好比来了个第三者,麻烦了...
iptables VS firewalld
最底层的实现是靠内核中的Netfilter,它是一个数据包过滤模块,而iptables和firewalld只是用户操作上的具体实现,也就是两个软件,不过体现在命令上他们都是iptables
,因此大家容易蒙圈。
当然firewalld功能上是优于iptables的,在规则管理上引入了区域的概念,也就是zones
;同时firewalld可以在不影响当前规则下加入新的规则,而iptables需要每次重新全部导入,这中间会有一个中断。
那再深一层的区别在哪里呢? 我也不懂,自己去查,我也是菜鸡
怎么解决?
回到问题,多数人在配置shipyard的时候都会遇到容器、镜像列表不显示的问题,
[图片上传失败...(image-5096af-1543459217561)]
研究了一下,shipyard在调用docker API的时候需要通过2375端口,开放它
还是不管用?
我也纳闷呢,开放了还是不管用,完蛋,禁用firewalld,单纯使用iptables来限制:
- 针对docker容器的iptables规则每次启动会重新检查,自动配置
- 排除firewalld带来的干扰
- 清空iptables规则从头开始
- 至于后续iptables规则造成的限制---哪里不通改哪里
有了上面的思路,先禁用firewalld
systemctl stop firewalld
systemctl mask firewalld
停止docker服务
systemctl stop docker
重置iptables规则
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
service iptables save
再次启动docker
systemctl start docker
浏览器访问,竟然直接就好了,,
毕竟shipyard放出来的版本不会有这么低级的错误,多半是环境所致。大多数的报错都是环境导致---这个锅运维背了!
贴一下重置后的iptables规则,仅供参考
iptables -L
[root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy DROP)
target prot opt source destination
DOCKER-USER all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-1 all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain DOCKER (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere 172.17.0.3 tcp dpt:afs3-callback
ACCEPT tcp -- anywhere 172.17.0.3 tcp dpt:newoak
ACCEPT tcp -- anywhere 172.17.0.4 tcp dpt:2375
ACCEPT tcp -- anywhere 172.17.0.8 tcp dpt:webcache
Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target prot opt source destination
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
RETURN all -- anywhere anywhere
Chain DOCKER-ISOLATION-STAGE-2 (1 references)
target prot opt source destination
DROP all -- anywhere anywhere
RETURN all -- anywhere anywhere
Chain DOCKER-USER (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
iptables -t nat -L
[root@localhost ~]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DOCKER all -- anywhere anywhere ADDRTYPE match dst-type LOCAL
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
DOCKER all -- anywhere !loopback/8 ADDRTYPE match dst-type LOCAL
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- 172.17.0.0/16 anywhere
MASQUERADE tcp -- 172.17.0.3 172.17.0.3 tcp dpt:afs3-callback
MASQUERADE tcp -- 172.17.0.3 172.17.0.3 tcp dpt:newoak
MASQUERADE tcp -- 172.17.0.4 172.17.0.4 tcp dpt:2375
MASQUERADE tcp -- 172.17.0.8 172.17.0.8 tcp dpt:webcache
Chain DOCKER (2 references)
target prot opt source destination
RETURN all -- anywhere anywhere
DNAT tcp -- anywhere anywhere tcp dpt:afs3-callback to:172.17.0.3:7001
DNAT tcp -- anywhere anywhere tcp dpt:newoak to:172.17.0.3:4001
DNAT tcp -- anywhere anywhere tcp dpt:2375 to:172.17.0.4:2375
DNAT tcp -- anywhere anywhere tcp dpt:webcache to:172.17.0.8:8080