# docker：守护进程响应错误：驱动在端点 container_name 上编程外部连接失败：（iptables 失败：iptables --wait -t nat -A DOCKER ! -i docker0 -p tcp --dport 8080 -j DNAT --to-destination 172.17.0.2:80 -m comment --comment "..." 失败：iptables：没有该名称的链/目标/匹配。）

- **ID:** `docker/port-mapping-ipv6-only`
- **领域:** docker
- **类别:** network_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

Docker 的 iptables 规则插入失败，因为 nat 表中的 DOCKER 链不存在，通常是由于在禁用 IPv6 或防火墙策略配置错误的系统上，Docker 被配置为使用 ip6tables 而不是 iptables。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Docker 20.10.24 | active | — | — |
| Docker 24.0.5 | active | — | — |
| Docker 25.0.1 | active | — | — |

## 解决方案

1. ```
   确保 iptables 内核模块已加载后重启 Docker 守护进程：'sudo modprobe iptable_nat && sudo modprobe iptable_filter'，然后 'sudo systemctl restart docker'。
   ```
2. ```
   如果主机上禁用了 IPv6，通过向 /etc/docker/daemon.json 添加 '{"ip6tables": false}' 来配置 Docker 仅使用 IPv4，然后重启 Docker。
   ```
3. ```
   完全重置 Docker 的网络状态：'sudo systemctl stop docker'，'sudo rm -rf /var/lib/docker/network'，然后 'sudo systemctl start docker'。这将强制 Docker 重新创建所有网络链。
   ```

## 无效尝试

- **** — Flushing all rules removes the DOCKER chain entirely, which is the root cause; Docker will fail to recreate it if the underlying issue (e.g., missing kernel module) persists. (70% 失败率)
- **** — This disables all port mapping and network isolation, breaking container connectivity; it is not a fix but a workaround that cripples networking. (40% 失败率)
- **** — While this may temporarily fix the error, Docker expects the chain to be created automatically; manual creation may conflict with Docker's internal state and cause instability. (50% 失败率)
