Docker 端口映射异常排查
容器启动时报 external connectivity 或 iptables 链缺失时,常见原因是防火墙重启后清掉了 Docker 注册的 NAT 链,导致端口映射规则无法写入。
典型现象
Error response from daemon:
driver failed programming external connectivity on endpoint
iptables: No chain/target/match by that name
排查方向
- 检查最近是否重启过 firewalld 或手动调整过 iptables
- 使用
iptables -L查看链是否存在 - 使用
iptables -t nat -nL查看 NAT 规则 - 重启 Docker 服务,让 Docker 重新注册相关链
处理命令
systemctl restart docker
iptables -t nat -nL
docker ps
这类问题本质上是网络规则状态被改动,处理时要注意业务容器是否允许重启,并尽量避开高峰时间。