docker下的oracle数据库服务存在漏洞,解决难度较高,于是通过firewalld限制高危端口开放,只允许本机访问。发现即使firewalld把oracle 1521漏洞不开放出去,但其他服务器依然能访问这给服务器的1521端口,也就是说firewalld配置的规则失效。
2.解决办法docker配置文件中添加 “iptables”: false
[root@localhost ~]# vi /etc/docker/daemon.json
{
"data-root": "/opt/docker",
"iptables": false
}
#重启生效
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart network
再次查看,firewalld配置的端口开放规则恢复正常。
3.引发问题后续发现加入 “iptables”: false参数后,容器内部无法与宿主机同网段的其他服务器通讯。
#网络不通 [root@localhost ~]# docker exec -it b287f29a1b60 bash root@b287f29a1b60:/usr/local/tomcat# ping 172.21.36.43 PING 172.21.36.43 (172.21.36.43) 56(84) bytes of data. ^C --- 172.21.36.43 ping statistics --- 8 packets transmitted, 0 received, 100% packet loss, time 9ms #iptables规则消失 [root@localhost ~]# iptables -nL Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination
解决方法:
在docker启动配置中加入配置
vi /etc/systemd/system/docker.service [Service] ExecStartPre=/usr/sbin/iptables -t nat -A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE ExecStopPost=/usr/sbin/iptables -t nat -D POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE #加载并重启docker systemctl daemon-reload systemctl restart docker
问题解决。



