泊坞窗未启动且出现错误,无法启动docker.service:找不到单元

时间:2020-09-14 04:26:26

标签: docker docker-compose

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

sudo systemctl start docker 

我遇到错误了

Failed to start docker.service: Unit not found.

我尝试在网络上找到一些建议来解决此问题,但随后并没有解决问题。

Cannot start docker daemon in CentOS7

这是我的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.

docker版本详细信息

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是一个问题。您能建议我如何解决吗?

1 个答案:

答案 0 :(得分:1)

/lib/systemd/system/etc/systemd/system上应该有一个docker.service单位文件。我的看起来像下面所示。

如果那里有一个,可以尝试通过以下方法确保已启用:

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