docker服务起不来原因及解决

2024-03-19 06:52

本文主要是介绍docker服务起不来原因及解决,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

  • 问题
  • 原因排查
    • 查看docker服务的状态
    • 尝试重启docker service
    • 查看 log分析原因
  • 解决方案参考
  • 解决过程

报错 关键词:
Failed to start Docker Application Container Engine.

Failed to find iptables: exec: \"iptables\": executable file not found in $PATH

failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: Iptables not found

问题

docker指令无法使用,docker服务未正确运行。

执行docker images,报错

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

无法连接docker daemon守护程序,无法连接服务socket,docker服务启动失败。

原因排查

查看docker服务的状态

执行 systemctl status docker 查看docker服务的状态
报错

● docker.service - Docker Application Container EngineLoaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)Active: failed (Result: exit-code) since Mon 2024-03-11 20:34:54 CST; 6 days agoDocs: https://docs.docker.comMain PID: 3548 (code=exited, status=1/FAILURE)Mar 11 20:34:54 test systemd[1]: docker.service: Service hold-off time over, scheduling restart.
Mar 11 20:34:54 test systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.
Mar 11 20:34:54 test systemd[1]: Stopped Docker Application Container Engine.
Mar 11 20:34:54 test systemd[1]: docker.service: Start request repeated too quickly.
Mar 11 20:34:54 test systemd[1]: docker.service: Failed with result 'exit-code'.
Mar 11 20:34:54 test systemd[1]: Failed to start Docker Application Container Engine.

显示启动 Docker Application Container Engine失败。

尝试重启docker service

执行:systemctl restart docker.service, 尝试重启docker service

root@test:/lib/systemd/system# systemctl restart docker.service
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.

无法启动。

查看 log分析原因

执行:journalctl -xe

Mar 18 13:28:40 test dockerd[24951]: time="2024-03-18T13:28:40.215890146+08:00" level=warning msg="Failed to find iptables: exec: \"iptables\": executable file not found in $PATH"
Mar 18 13:28:40 test dockerd[24951]: time="2024-03-18T13:28:40.218084167+08:00" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd namespace=moby
Mar 18 13:28:40 test dockerd[24951]: failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: Iptables not found
Mar 18 13:28:40 test systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
Mar 18 13:28:40 test systemd[1]: docker.service: Failed with result 'exit-code'.
-- Subject: Unit docker.service has failed
-- Unit docker.service has failed.

可以看出来是iptables找不到,这个服务没开起来,导致docker服务起不来。
执行systemctl status iptables

root@test:/lib/systemd/system# systemctl status iptables
Unit iptables.service could not be found.

无法找到 iptables.service;有可能是该服务没起来,没安装,或者 iptables 实际上未作为服务运行,而是系统调用。

解决方案参考

参考chatgpt3.5答案:

如果系统中找不到 iptables 服务单元(Unit),这可能意味着 iptables 实际上未作为服务运行。在某些系统上,iptables 配置可能直接由系统调用而不是通过单独的服务。 在这种情况下,您可以尝试按照以下步骤解决Docker无法启动的问题:

  1. 检查 iptables 是否安装:首先,请确保 iptables 工具已安装在系统中。您可以使用以下命令检查 iptables 的安装状态:

which iptables

如果该命令返回路径,则表示 iptables 已安装。如果没有返回任何内容,您可能需要安装 iptables

  1. 手动加载 iptable_nat 模块:有时,即使 iptables 安装了,其相关内核模块也可能未加载。您可以尝试手动加载iptable_nat内核模块:

modprobe iptable_nat

  1. 启用 IP 转发:确保在 sysctl 配置中启用了 IP 转发。您可以编辑 /etc/sysctl.conf 文件并确保以下行未被注释(去掉前面的 # 符号),(在后面追加下面的代码)

net.ipv4.ip_forward = 1

保存文件后,运行以下命令以使更改生效:

sudo sysctl -p

  1. 重新启动 Docker 服务:一旦您已确保 iptables 正常工作并将所需的内核模块加载到系统中,尝试重新启动 Docker 服务

sudo systemctl restart docker

解决过程

尝试按照上述方案进行修改:
执行:
apt-get update && apt install iptables
显示已经安装
再次执行 systemctl status iptables
显示

root@test:/lib/systemd/system# systemctl status iptables
Unit iptables.service could not be found.

说明iptables 配置可能直接由系统调用,而不是服务
执行

root@test:/lib/systemd/system# which iptables
/sbin/iptables
root@test:/lib/systemd/system# modprobe iptable_nat
root@test:/lib/systemd/system# vi /etc/sysctl.conf
root@test:/lib/systemd/system# sysctl -p
fs.file-max = 2097152
net.ipv4.ip_forward = 1
root@test:/lib/systemd/system# systemctl status iptables
Unit iptables.service could not be found.
root@test:/lib/systemd/system# systemctl restart docker.service
root@test:/lib/systemd/system# systemctl status docker.service
● docker.service - Docker Application Container EngineLoaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)Active: active (running) since Mon 2024-03-18 13:33:44 CST; 7s agoDocs: https://docs.docker.comMain PID: 28879 (dockerd)Tasks: 20CGroup: /system.slice/docker.service└─28879 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

运行成功

这篇关于docker服务起不来原因及解决的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/825142

相关文章

C++右移运算符的一个小坑及解决

《C++右移运算符的一个小坑及解决》文章指出右移运算符处理负数时左侧补1导致死循环,与除法行为不同,强调需注意补码机制以正确统计二进制1的个数... 目录我遇到了这么一个www.chinasem.cn函数由此可以看到也很好理解总结我遇到了这么一个函数template<typename T>unsigned

通过Docker容器部署Python环境的全流程

《通过Docker容器部署Python环境的全流程》在现代化开发流程中,Docker因其轻量化、环境隔离和跨平台一致性的特性,已成为部署Python应用的标准工具,本文将详细演示如何通过Docker容... 目录引言一、docker与python的协同优势二、核心步骤详解三、进阶配置技巧四、生产环境最佳实践

java.sql.SQLTransientConnectionException连接超时异常原因及解决方案

《java.sql.SQLTransientConnectionException连接超时异常原因及解决方案》:本文主要介绍java.sql.SQLTransientConnectionExcep... 目录一、引言二、异常信息分析三、可能的原因3.1 连接池配置不合理3.2 数据库负载过高3.3 连接泄漏

使用docker搭建嵌入式Linux开发环境

《使用docker搭建嵌入式Linux开发环境》本文主要介绍了使用docker搭建嵌入式Linux开发环境,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录1、前言2、安装docker3、编写容器管理脚本4、创建容器1、前言在日常开发全志、rk等不同

sysmain服务可以禁用吗? 电脑sysmain服务关闭后的影响与操作指南

《sysmain服务可以禁用吗?电脑sysmain服务关闭后的影响与操作指南》在Windows系统中,SysMain服务(原名Superfetch)作为一个旨在提升系统性能的关键组件,一直备受用户关... 在使用 Windows 系统时,有时候真有点像在「开盲盒」。全新安装系统后的「默认设置」,往往并不尽编

504 Gateway Timeout网关超时的根源及完美解决方法

《504GatewayTimeout网关超时的根源及完美解决方法》在日常开发和运维过程中,504GatewayTimeout错误是常见的网络问题之一,尤其是在使用反向代理(如Nginx)或... 目录引言为什么会出现 504 错误?1. 探索 504 Gateway Timeout 错误的根源 1.1 后端

解决升级JDK报错:module java.base does not“opens java.lang.reflect“to unnamed module问题

《解决升级JDK报错:modulejava.basedoesnot“opensjava.lang.reflect“tounnamedmodule问题》SpringBoot启动错误源于Jav... 目录问题描述原因分析解决方案总结问题描述启动sprintboot时报以下错误原因分析编程异js常是由Ja

Python 基于http.server模块实现简单http服务的代码举例

《Python基于http.server模块实现简单http服务的代码举例》Pythonhttp.server模块通过继承BaseHTTPRequestHandler处理HTTP请求,使用Threa... 目录测试环境代码实现相关介绍模块简介类及相关函数简介参考链接测试环境win11专业版python

深度剖析SpringBoot日志性能提升的原因与解决

《深度剖析SpringBoot日志性能提升的原因与解决》日志记录本该是辅助工具,却为何成了性能瓶颈,SpringBoot如何用代码彻底破解日志导致的高延迟问题,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言第一章:日志性能陷阱的底层原理1.1 日志级别的“双刃剑”效应1.2 同步日志的“吞吐量杀手”

MySQL 表空却 ibd 文件过大的问题及解决方法

《MySQL表空却ibd文件过大的问题及解决方法》本文给大家介绍MySQL表空却ibd文件过大的问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考... 目录一、问题背景:表空却 “吃满” 磁盘的怪事二、问题复现:一步步编程还原异常场景1. 准备测试源表与数据