首页 > 解决方案 > docker 未启动且失败并出现错误,无法启动 docker.service: Unit not found

问题描述

当我尝试使用以下命令启动 docker 时:

sudo systemctl start docker 

我得到以下错误

Failed to start docker.service: Unit not found.

我尝试在网上找到一些解决此问题的建议并遵循,但它并没有解决问题。

在 CentOS7 中无法启动 docker daemon

这是我的 docker.socket 文件[这只是答案之一的复制粘贴]

[Unit]
Description=Docker Socket for the API
PartOf=docker.service

[Socket]
ListenStream=/var/run/docker.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker

[Install]
WantedBy=sockets.target

这是我在启动 docker.socket 时遇到的错误

sudo systemctl start docker.socket

See "systemctl status docker.socket" and "journalctl -xe" for details.

“systemctl status docker.socket”的输出

systemctl status docker.socket

systemd[1]: Socket service docker.service not loaded, refusing.
systemd[1]: Failed to listen on Docker Socket for the API.

码头工人版本详细信息

Client: Docker Engine - Community
 Version:           19.03.2
 API version:       1.40
 Go version:        go1.12.8
 Git commit:        6a30dfca03
 Built:             Thu Aug 29 05:26:30 2019
 OS/Arch:           linux/amd64
 Experimental:      false
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

对我来说, docker.service 似乎是个问题。您能否建议我如何解决它。

标签: dockerdocker-compose

解决方案


/lib/systemd/system在或中应该有一个 docker.service 单元文件/etc/systemd/system。我的看起来如下图所示。

如果你有一个,你可以尝试确保它通过以下方式启用:

sudo systemctl enable docker.service

这是 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

[Install]
WantedBy=multi-user.target

推荐阅读