docker0: iptables: No chain/target/match by that name

本文记录了在尝试启动一个名为some-piwik的Docker容器时遇到的问题及解决过程。主要错误为Docker守护进程在配置外部连接时失败,具体涉及到iptables命令未能正确设置端口映射。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[root@iZuf6boi8ejfovwda7q1ynZ ~]# docker start some-piwik
Error response from daemon: driver failed programming external connectivity on endpoint some-piwik (2ef09f672f43162e281d97f30a21dd392c56c2bb72acd5cc6fb093245831fba2): iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8082 -j DNAT --to-destination 192.168.0.5:80 ! -i docker0: iptables: No chain/target/match by that name.

1:停止docker

[root@iZuf6boi8ejfovwda7q1ynZ ~]# service docker stop

Redirecting to /bin/systemctl stop docker.service

[root@iZuf6boi8ejfovwda7q1ynZ ~]# docker ps

Cannot connect to the Docker daemon. Is the docker daemon running on this host?

2:保存iptables

[root@iZuf6boi8ejfovwda7q1ynZ ~]# iptables-save >  /etc/sysconfig/iptables

3:启动docker

[root@iZuf6boi8ejfovwda7q1ynZ ~]# service docker start

Redirecting to /bin/systemctl start docker.service

[root@iZuf6boi8ejfovwda7q1ynZ ~]# docker start some-piwik
some-piwik

### Dockeriptables 配置导致外部连接性编程失败问题的解决方案 当在 CentOS 或其他 Linux 发行版上运行 Docker 容器时,如果遇到 `iptables: No chain/target/match by that name` 错误,则可能是由于防火墙服务未正常启动或 Docker 的网络链尚未正确加载到系统的 `iptables` 表中。 以下是针对该问题的具体分析和解决办法: #### 1. **确认 Firewalld 和 Iptables 状态** CentOS 7 默认使用 `firewalld` 替代传统的 `iptables`。然而,Docker 在内部仍然依赖于 `iptables` 来管理其 NAT 表中的规则。因此,需要确保两者之间的兼容性[^5]。 - 如果 `firewalld` 已启用,可以尝试禁用它并切换回传统模式: ```bash systemctl stop firewalld systemctl disable firewalld ``` - 接着安装并启用 `iptables-services`: ```bash yum install -y iptables-services systemctl start iptables systemctl enable iptables ``` #### 2. **重启 Docker 服务** 无论是否启用了 `firewalld`,都需要重新启动 Docker 服务以确保其自定义的 `DOCKER` 链被正确注入到 `iptables` 的 NAT 表中。 ```bash systemctl restart docker ``` 此操作会触发 Docker 自动向 `iptables` 添加必要的规则集。 #### 3. **手动添加缺失的 Chain** 如果上述方法未能解决问题,可以通过命令行手工验证是否存在名为 `DOCKER` 的链,并视情况补充之: ```bash iptables -t nat -L | grep DOCKER ``` 如果没有找到对应的条目,则需显式创建这一链条及其关联规则: ```bash iptables -t nat -N DOCKER iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER iptables -t nat -A OUTPUT ! -o lo -m owner --uid-owner root -j RETURN iptables -t nat -A OUTPUT -m addrtype --dst-type LOCAL -j DOCKER ``` 以上脚本片段用于初始化基础结构以便支持后续动态映射需求[^4]。 #### 4. **调整 SELinux 设置** 某些情况下,默认的安全增强策略可能干扰了容器对外部资源的访问权限。此时可考虑临时关闭 SELinux 测试效果或者修改相关文件标签来适配环境要求[^1]: 编辑 `/etc/selinux/config` 文件并将其中参数设为 permissive 模式: ```ini SELINUX=permissive ``` 随后执行 reboot 命令完成更改生效过程. #### 5. **检查 MySQL 容器端口绑定** 对于特定应用如 MySQL 数据库实例而言,还需特别留意宿主机上的监听地址与目标服务间的匹配关系。例如通过如下方式指定明确映射关系能有效规避潜在冲突风险[^2]: ```yaml ports: - "host_port:mysql_container_port" example: ports: - "3306:3306" ``` 最后再次强调务必同步更新对应云平台控制台内的安全组配置允许入方向流量到达所设定好的公开接口之上。 --- ### 总结 综上所述,处理此类错误通常涉及以下几个方面的工作:一是保障底层防护机制处于预期工作状态;二是按需定制化构建适合当前场景下的路由转发路径;三是合理规划各层之间交互逻辑从而达成无缝衔接目的。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值