重启容器报如下错误:
Error response from daemon: Cannot restart container jenkins-master: driver failed programming external connectivity on endpoint jenkins-master (e0381ec52a0f8c769ea6710d8591771a8043f193d818d9d9f74ff2dd1bd2cc4e): (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 50000 -j DNAT --to-destination 172.17.0.2:50000 ! -i docker0: (fork/exec /usr/sbin/iptables: no such file or directory))
解决:
1、重启docker
服务
systemctl restart docker
2、docker
服务启动失败
Sep 05 15:04:19 xa197 dockerd[447471]: time="2024-09-05T15:04:19.074250301+08:00" level=info msg="Starting up"
Sep 05 15:04:19 xa197 dockerd[447471]: time="2024-09-05T15:04:19.074877662+08:00" level=info msg="detected 127.0.0.53 nameserver, assuming systemd-resolved, so using resolv.conf: /run/systemd/resolve/resolv.conf"
Sep 05 15:04:19 xa197 dockerd[447471]: time="2024-09-05T15:04:19.092497066+08:00" level=info msg="[graphdriver] using prior storage driver: overlay2"
Sep 05 15:04:19 xa197 dockerd[447471]: time="2024-09-05T15:04:19.108106553+08:00" level=info msg="Loading containers: start."
Sep 05 15:04:19 xa197 dockerd[447471]: time="2024-09-05T15:04:19.131414749+08:00" level=warning msg="failed to find iptables" error="exec: \"iptables\": executable file not found in $PATH"
Sep 05 15:04:19 xa197 dockerd[447471]: time="2024-09-05T15:04:19.132372573+08:00" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd namespace=moby
Sep 05 15:04:19 xa197 dockerd[447471]: failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: Iptables not found
Sep 05 15:04:19 xa197 dockerd[447471]: time="2024-09-05T15:04:19.132699258+08:00" level=info msg="stopping event stream following graceful shutdown" error="context canceled" module=libcontainerd namespace=plugins.moby
Sep 05 15:04:19 xa197 systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
检查 iptables
是否安装:首先,请确保 iptables
工具已安装在系统中。您可以使用以下命令检查 iptables
的安装状态:
which iptables
如果该命令返回路径,则表示iptables
已安装。如果没有返回任何内容,您可能需要安装 iptables。
apt install iptables
手动加载 iptable_nat
模块:有时,即使 iptables
安装了,其相关内核模块也可能未加载。您可以尝试手动加载iptable_nat
内核模块:
modprobe iptable_nat
启用 IP 转发:确保在sysctl
配置中启用了 IP 转发。您可以编辑 /etc/sysctl.conf
文件并确保以下行未被注释(去掉前面的 # 符号),(在后面追加下面的代码)
net.ipv4.ip_forward = 1
保存文件后,运行以下命令以使更改生效:
sudo sysctl -p
重新启动 Docker
服务:一旦您已确保 iptables
正常工作并将所需的内核模块加载到系统中,尝试重新启动 Docker
服务:
sudo systemctl restart docker
3、重启相应容器
docker restart jenkins-master
参考链接:
https://blog.csdn.net/qq_40804558/article/details/136807276
网友评论