Docker故障

故障背景:

今天启动docker容器并进行端口映射时发现报错,无法进行端口映射了,报错如下:

[root@kvm66 ~]# docker run -d -p 20024:22 centos-ssh /usr/sbin/sshd -D

63f7d417b2dbf0026e0bb6da631ad64bf6ece14a8fd05f519d54892fe5bd5447

Error response from daemon: Cannot start container 63f7d417b2dbf0026e0bb6da631ad64bf6ece14a8fd05f519d54892fe5bd5447: iptables failed: iptables -t nat -A DOCKER -p tcp -d 0/0 --dport 20024 -j DNAT --to-destination 172.17.0.24:22 ! -i docker0: iptables: No chain/target/match by that name.

然后想起来前几天服务器远程连接出现问题,自己把防火墙关闭了

解决办法:

把需要保存的容器,提交镜像

[root@kvm66 ~]# docker commit 688a2b65fe6e blue-zk

1e44a667d2fc0523718019f57ee9a1563d3ba9ab49a6fb840a43e9e664b37ca2

[root@kvm66 ~]# docker images

REPOSITORY                 TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

blue-zk                    latest              1e44a667d2fc        25 seconds ago      945.3 MB

[root@kvm66 ~]# /etc/init.d/docker stop

停止docker                                             [确定]

[root@kvm66 ~]# iptables -t nat -F

[root@kvm66 ~]# ifconfig docker0 down

[root@kvm66 ~]# brctl delbr docker0

之后重启docker即可

[root@kvm66 ~]# /etc/init.d/docker status

启动容器进行端口映射