既然 Docker 已经安装了,但你还是收到 Unit docker.service not found 的错误消息,这可能是由于 Docker 服务文件没有正确安装或配置。以下是你可以采取的步骤来解决这个问题:
1. 检查 Docker 服务文件
确认 Docker 服务文件是否存在于正确的位置:
bash
复制代码
ls /lib/systemd/system/docker.service
或
bash
复制代码
ls /etc/systemd/system/docker.service
2. 手动创建 Docker 服务文件
如果服务文件不存在,你可以手动创建它。创建一个名为 docker.service 的文件并添加以下内容:
bash
复制代码
sudo nano /lib/systemd/system/docker.service
然后添加以下内容:
ini
复制代码
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd -H unix://
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.
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
保存并退出编辑器。
3. 重新加载 Systemd 并启动 Docker
bash
复制代码
sudo systemctl daemon-reload
sudo systemctl start docker
sudo systemctl enable docker
4. 检查 Docker 服务状态
bash
复制代码
sudo systemctl status docker
如果服务启动成功,你应该看到 Docker 服务正在运行。
5. 重启 Docker
现在你可以重启 Docker 了。
bash
复制代码
sudo systemctl restart docker
如果上述步骤仍然无法解决问题,请提供更多细节,以便进一步排查。 |