无法启动Docker服务,出现错误“无法启动Docker,service:未找到单位,”

xfb7svmp  于 2023-05-16  发布在  Docker
关注(0)|答案(9)|浏览(326)

我用yum install docker安装了Docker:

$ uname -a
Linux caspgval4 3.10.0-229.20.1.el7.x86_64 #1 SMP Wed Nov 4 10:08:36 CST 2015 x86_64 x86_64 x86_64 GNU/Linux

$ docker --version
Docker version 1.12.6, build 3a094bd/1.12.6

$ docker info
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: http://docs.docker.com

我正在尝试安装和运行Docker,但它给出了如下错误:

$ sudo service docker start
Redirecting to /bin/systemctl start  docker.service
Failed to start docker.service: Unit not found.

如何解决此问题?我尝试了以下命令,但没有成功:

$ sudo systemctl start docker
Failed to start docker.service: Unit not found.

额外信息:

$ journalctl -u docker
No journal files were found.
-- No entries --

$ cat /usr/lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target
Wants=docker-storage-setup.service
Requires=rhel-push-plugin.socket
Requires=docker-cleanup.timer

[Service]
Type=notify
NotifyAccess=all
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current \
          --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
          --default-runtime=docker-runc \
          --authorization-plugin=rhel-push-plugin \
          --exec-opt native.cgroupdriver=systemd \
          --userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
          $OPTIONS \
          $DOCKER_STORAGE_OPTIONS \
          $DOCKER_NETWORK_OPTIONS \
          $ADD_REGISTRY \
          $BLOCK_REGISTRY \
          $INSECURE_REGISTRY
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
MountFlags=slave

[Install]
WantedBy=multi-user.target

我尝试了以下方法:

$ sudo systemctl daemon-reload
$ sudo systemctl start docker
Failed to start docker.service: Unit not found.
$ sudo journalctl -u docker
-- No entries --

更多调试信息:

$ sudo systemctl status network.target
● network.target - Network
   Loaded: loaded (/usr/lib/systemd/system/network.target; static; vendor preset: disabled)
   Active: active since Mon 2017-01-23 02:54:39 PST; 2 months 29 days ago
     Docs: man:systemd.special(7)
           http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget

Jan 23 02:54:39 mymachine systemd[1]: Starting Network.
Jan 23 02:54:39 mymachine systemd[1]: Reached target Network.

$ sudo systemctl status docker-storage-setup.service
● docker-storage-setup.service - Docker Storage Setup
   Loaded: loaded (/usr/lib/systemd/system/docker-storage-setup.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

$ sudo systemctl status rhel-push-plugin.socket
Unit rhel-push-plugin.socket could not be found.

$ sudo systemctl status docker-cleanup.timer
● docker-cleanup.timer - Run docker-cleanup every hour
   Loaded: loaded (/usr/lib/systemd/system/docker-cleanup.timer; disabled; vendor preset: disabled)
   Active: inactive (dead)
mbyulnm0

mbyulnm01#

运行此命令以列出所有服务:

sudo systemctl list-units --type=service

查找正确的Docker服务名称(在我的例子中是snap.docker.dockerd.service),然后运行:

sudo systemctl restart snap.docker.dockerd.service
qgelzfjb

qgelzfjb2#

如果有人使用snap安装了docker,他们可以使用

sudo snap status docker #check the status
sudo snap start docker # start the service
tag5nh1u

tag5nh1u3#

看起来你缺少了rhel-push-plugin.socket单元,它可能是rhel-push-plugin包的一部分。您可以尝试修复该安装,或者您可以直接从Docker安装上游Docker包,并以root用户身份安装:

curl -sSL https://get.docker.com/ | sh

或者更恰当地遵循CentOS install guide from Docker。(CentOS安装倾向于在RHEL系统上工作,即使你有一个支持的版本,直到最近的20.10版本不包括CentOS 8或RHEL 8。
上游Docker安装将是Docker的最新版本,但它不会有各种RHEL修改,如rhel-push-plugin。

kx7yvsdv

kx7yvsdv4#

如果您的操作系统是Ubuntu,请使用以下命令,它将成功安装Docker:

apt install docker.io
jucafojl

jucafojl5#

如果你已经安装了带有snap的docker,你可以像这样检查守护进程的状态:

sudo snap services docker

如果current列显示inactive,则它没有运行。试着从这个开始:

sudo snap start docker

再次检查服务,如果之后它仍然没有运行,您可以检查日志:

sudo snap logs docker

这可能会给予更多的线索,告诉我们是什么阻止了它的运行
对我来说,我有一个错误,说docker无法在/etc/docker/中创建符号链接,因为另一个文件在路上。由于docker snap中的已知错误,清空目录是不够的。解决方法是删除目录,然后刷新快照(请参见https://forum.snapcraft.io/t/layouts-still-brittle-when-refreshing-snaps/26252/2

sudo rm -rf /etc/docker
sudo snap refresh
6l7fqoea

6l7fqoea6#

我通过简单地做以下事情来解决这个问题:

$ sudo apt-get purge containerd.io docker-ce
$ rm -rf /var/lib/containerd
[reboot]
$ sudo apt-get install containerd.io docker-ce
qgzx9mmu

qgzx9mmu7#

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/docker-basics.html
注记
在某些情况下,您可能需要重新启动示例,以便为ec2-user提供访问Docker守护进程的权限。如果看到以下错误,请尝试重新启动示例:

km0tfn4u

km0tfn4u8#

在Ubuntu中,以下命令对我有效:
sudo apt install docker.io

kqhtkvqz

kqhtkvqz9#

尝试以root身份安装Docker(sudo):

sudo yum install docker

参见 Installation on Red Hat Enterprise Linux

相关问题