firewalld防火墙开启后无法启动docker的问题 2、让Docker 绕过了 firewalld

1、错误场景和现象

linux开启或重启防火墙后,创建docker自定义网络时

docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 frayernet

报错:[root@VM-16-5-centos home]# docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 frayernet
Error response from daemon: Failed to Setup IP tables: Unable to enable SKIP DNAT rule:  (iptables failed: iptables --wait -t nat -I DOCKER -i br-3d8c7623fb81 -j RETURN: iptables: No chain/target/match by that name.
 (exit status 1))

如下:

[root@VM-16-5-centos home]# docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 frayernet
Error response from daemon: Failed to Setup IP tables: Unable to enable SKIP DNAT rule:  (iptables failed: iptables --wait -t nat -I DOCKER -i br-3d8c7623fb81 -j RETURN: iptables: No chain/target/match by that name.
 (exit status 1))

2、原因分析

Docker属于容器化技术,如果宿主机防火墙的状态发生了改变,Docker就无法设置容器的IP了

测试尝试启动一个已经存在的mysql容器

[root@VM-16-5-centos conf]# docker start c092

同样会出现错误:

Error response from daemon: driver failed programming external connectivity on endpoint mysql5.7-cdcs-cd (ac43ff409d232efe3eace11b5f2b9d08b8f98c949e7fb43323bc289240560e38):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 3306 -j DNAT --to-destination 172.17.0.3:3306 ! -i docker0: iptables: No chain/target/match by that name.
 (exit status 1))
Error: failed to start containers: c092

3、解决办法

1、输入命令service docker restart重启以下Docker即可
[root@VM-16-5-centos home]# service docker restart

出现次问题的原因:

irewall的底层是使用iptables进行数据过滤,建立在iptables之上,而docker使用iptables来进行网络隔离和管理,这可能会与 Docker 产生冲突。当 firewalld 启动或者重启的时候,将会从 iptables 中移除 DOCKER 的规则,从而影响了 Docker 的正常工作。

也就是说,firewalld和docker都在操作iptables的规则,但是docker和firewalld发生了冲突,导致docker和firewall的设置的不一致,所以出现了问题。

 

2、让Docker 绕过了 firewalld 

我们让docker不修改 iptables 就可以解决问题了:

##修改docker配置
vim /etc/docker/daemon.json
 
# 添加规则
{
...
"experimental" : true,
"iptables": false
}
 
# 重启 docker
systemctl daemon-reload
systemctl restart docker
 
# 启动容器
docker run -d -p 80:80 nginx
# 查看iptables规则 发现 docker 没有添加规则
iptables --list
 

相关推荐

  1. Linux中防火墙————Firewalld

    2023-12-22 18:50:02       13 阅读
  2. RHEL/CentOSfirewalld防火墙服务配置

    2023-12-22 18:50:02       42 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-22 18:50:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-22 18:50:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-22 18:50:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-22 18:50:02       18 阅读

热门阅读

  1. Cookie中的Expiry标示是什么

    2023-12-22 18:50:02       35 阅读
  2. ZooKeeper 集群搭建

    2023-12-22 18:50:02       40 阅读
  3. OpenVAS 故障排除

    2023-12-22 18:50:02       35 阅读
  4. FlinkSQL

    FlinkSQL

    2023-12-22 18:50:02      30 阅读
  5. Android Studio 显示Cause: connect timed out

    2023-12-22 18:50:02       38 阅读
  6. day6 力扣公共前缀--go实现---对字符串的一些思考

    2023-12-22 18:50:02       41 阅读
  7. hive中array相关函数总结

    2023-12-22 18:50:02       44 阅读