其實應該說是docker和這兩者之間的恩怨情仇
爲什麼這麼說?因爲每當docker服務在啓動的時候,都會根據自己的網絡情況(如docker0網橋)、容器地址分配情況自動配置iptables規則,本來這很正常,規則有序。
不巧的是centos7中冒出來一個firewalld,這就好比來了個第三者,麻煩了...
iptables VS firewalld
最底層的實現是靠內核中的Netfilter,它是一個數據包過濾模塊,而iptables和firewalld只是用戶操作上的具體實現,也就是兩個軟件,不過體現在命令上他們都是iptables
,因此大家容易蒙圈。
當然firewalld功能上是優於iptables的,在規則管理上引入了區域的概念,也就是zones
;同時firewalld可以在不影響當前規則下加入新的規則,而iptables需要每次重新全部導入,這中間會有一箇中斷。
那再深一層的區別在哪裏呢? 我也不懂,自己去查,我也是菜雞
怎麼解決?
回到問題,多數人在配置shipyard的時候都會遇到容器、鏡像列表不顯示的問題,
研究了一下,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