运行:docker run -p 8080:8080 zstest
报错:
docker: Error response from daemon: driver failed programming external connectivity on endpoint agitated_perlman (5b968b19e9cb3ee66f8186079209771ac2c52b64579f8909d5e70337dede4e3e): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8080 -j DNAT --to-destination 172.17.0.3:8080 ! -i docker0: iptables: No chain/target/match by that name.
1、停止docker服务
输入如下命令停止docker服务
systemctl stop docker
service docker stop
2、保存 iptables
输入如下命令:
iptables-save > /etc/sysconfig/iptables
保存之后的文件内容:
# Generated by iptables-save v1.4.21 on Sat Nov 24 13:53:13 2018
*nat
:PREROUTING ACCEPT [261:18558]
:INPUT ACCEPT [17:969]
:OUTPUT ACCEPT [4:304]
:POSTROUTING ACCEPT [4:304]
COMMIT
# Completed on Sat Nov 24 13:53:13 2018
# Generated by iptables-save v1.4.21 on Sat Nov 24 13:53:13 2018
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1246:135222]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10001 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10002 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10003 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10004 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Sat Nov 24 13:53:13 2018
3、启动docker服务
保存了iptables后,可以重新启动docker了。输入如下命令:
systemctl start docker 或者service docker start
4、将docker设置为开机启动
设置过这个就不需要再设置了
5、启动容器
最后启动容器,发现不再报错了。
docker run -p 8080:8080 zstest
转自:Docker运行镜像报错处理 docker0: iptables: No chain/target/match by that name. - 崔安兵 - 博客园 (cnblogs.com)
亲测可用