Debian系统Docker无法通过systemctl启动故障求助
解决Docker无法通过systemctl启动的问题
看起来你的docker.service配置文件被损坏了——它现在只有环境变量行,缺少了systemd服务必需的[Service]段和核心启动指令,这就是为什么systemctl报错说缺少ExecStart=和ExecStop=设置的原因。下面是具体的修复步骤:
步骤1:备份当前损坏的配置文件
先把现在的文件存个备份,避免后续操作出问题没法恢复:
sudo cp /lib/systemd/system/docker.service /lib/systemd/system/docker.service.bak
步骤2:重新生成正确的docker.service配置
对于Debian 9上的Docker 19.03版本,正确的docker.service应该包含完整的服务定义。你可以用下面的内容覆盖当前文件:
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com BindsTo=containerd.service After=network-online.target firewalld.service containerd.service Wants=network-online.target Requires=docker.socket [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ExecReload=/bin/kill -s HUP $MAINPID TimeoutSec=0 RestartSec=2 Restart=always # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229. # Both the old, and new location are accepted by systemd 229 and up, so using the old location # to make them work for either version of systemd. StartLimitBurst=3 # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230. # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make # this option work for either version of systemd. StartLimitInterval=60s # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Comment TasksMax if your systemd version does not support it. # Only systemd 226 and above support this option. TasksMax=infinity # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process # restart the docker process if it exits prematurely Restart=on-failure StartLimitBurst=3 StartLimitInterval=60s # 添加你原来的环境变量 Environment="GOOGLE_APPLICATION_CREDENTIALS=/etc/docker/key.json" [Install] WantedBy=multi-user.target
执行命令编辑文件并粘贴内容:
sudo nano /lib/systemd/system/docker.service # 粘贴上述内容后,按Ctrl+O保存,回车确认,再按Ctrl+X退出编辑器
步骤3:重新加载systemd配置并启动Docker
# 重新加载systemd的配置文件,让新的service生效 sudo systemctl daemon-reload # 启动Docker服务 sudo systemctl start docker # (可选)设置Docker开机自动启动 sudo systemctl enable docker
步骤4:验证服务状态
执行下面的命令确认Docker已经正常运行:
systemctl status docker
如果输出显示active (running),就说明问题已经解决了。
补充说明
大概率是VM内存耗尽崩溃时,docker.service文件被异常损坏——系统突然断电/崩溃可能导致文件内容丢失或被篡改。现在我们恢复了完整的服务配置框架,同时保留了你需要的环境变量,systemd就能正确识别并管理Docker服务了。
内容的提问来源于stack exchange,提问作者DarkLeafyGreen
相关产品推荐
相关产品推荐

