由于 docker.service 尝试在 docker.socket 之前启动,导致 Docker 安装失败

由于 docker.service 尝试在 docker.socket 之前启动,导致 Docker 安装失败

我正在尝试通过以下方式在机器上安装docker:

apt-get --allow-downgrades -yq install docker-ce=18.06.3*

这会导致安装后脚本出现错误:

● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Thu 2021-09-02 18:17:18 EDT; 3ms ago
     Docs: https://docs.docker.com
  Process: 17110 ExecStart=/usr/bin/dockerd -H fd:// (code=exited, status=1/FAILURE)
 Main PID: 17110 (code=exited, status=1/FAILURE)
dpkg: error processing package docker-ce (--configure):
 installed docker-ce package post-installation script subprocess returned error exit status 1
Processing triggers for systemd (237-3ubuntu10.51) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Errors were encountered while processing:
 docker-ce

查看 journalctl -xe:

-- Unit docker.service has begun starting up.
Sep 02 16:44:20 office64-001 dockerd[20320]: Failed to load listeners: no sockets found via socket activation: make sure the service was started by systemd
Sep 02 16:44:20 office64-001 systemd[1]: docker.service: Main process exited, code=exited, status=1/FAILURE
Sep 02 16:44:20 office64-001 systemd[1]: docker.service: Failed with result 'exit-code'.
Sep 02 16:44:20 office64-001 systemd[1]: Failed to start Docker Application Container Engine.

上述错误发生在 16:44:20。然后,查看 journalctl -u docker.socket 的输出:

Sep 02 16:44:21 office64-001 systemd[1]: Starting Docker Socket for the API.
Sep 02 16:44:21 office64-001 systemd[1]: Listening on Docker Socket for the API.

上述错误发生一秒后,套接字似乎变为活动状态。

此后,docker 尝试重新启动并成功,因为套接字有机会变为活动状态。然而,我的理解是docker.service 应该等待 docker.socket 准备就绪.来自docker.service:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service
Wants=network-online.target
Requires=docker.socket

我的问题是我有一个脚本,只要安装失败它就会失败,因此即使看起来 docker 已正确安装,它也会在安装时导致问题,从而阻止脚本正常运行。

有任何想法吗?

相关内容