如何修复“找不到单元 docker.service。”错误?

如何修复“找不到单元 docker.service。”错误?

我如何简单地拉动并运行hello-world

nicholas@mordor:~$ 
nicholas@mordor:~$ 
nicholas@mordor:~$ snap list docker
Name    Version   Rev   Tracking       Publisher   Notes
docker  20.10.14  1779  latest/stable  canonical✓  -
nicholas@mordor:~$ 
nicholas@mordor:~$ sudo docker pull hello-world
Using default tag: latest
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
nicholas@mordor:~$ 
nicholas@mordor:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:    22.04
Codename:   jammy
nicholas@mordor:~$ 
nicholas@mordor:~$ sudo systemctl start docker
Failed to start docker.service: Unit docker.service not found.
nicholas@mordor:~$ 
nicholas@mordor:~$ sudo systemctl status docker
Unit docker.service could not be found.
nicholas@mordor:~$ 

也可以看看:

https://stackoverflow.com/questions/44678725/cannot-connect-to-the-docker-daemon-at-unix-var-run-docker-sock-is-the-docker

找不到单元 docker.service

答案1

就我而言,为了解决“无法找到 Unit docker.service”问题,我需要运行...

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

(来源:https://docs.docker.com/engine/install/ubuntu/

答案2

docker 的 snap 版本可能只是 docker 客户端,而不是实际的 docker 守护进程和服务。我建议访问他们的网站并尝试按照他们的说明进行安装,因为它可能有完整的软件包

指示这里对于 Ubuntu

答案3

就我的情况来说,从 .deb 文件安装 Docker Desktop 后,我运行

sudo apt-get install docker-ce

之后,我尝试运行该服务

systemctl start docker

成功了!之前我运行sudo apt --fix-broken install安装docker .deb文件失败时,并没有提示需要docker-ce。后来才发现需要docker-ce。

答案4

这个选项对我有帮助: 1. for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done 2. sudo apt-get update sudo apt-get install ca-certificates curl sudo install -m 0755 -d /etc/apt/keyrings sudo curl -fsSLhttps://download.docker.com/linux/ubuntu/gpg-o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc

echo
“deb [arch=$(dpkg --print-architecture)signed-by=/etc/apt/keyrings/docker.asc]https://download.docker.com/linux/ubuntu
$(. /etc/os-release && echo "$VERSION_CODENAME") 稳定" |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get 更新

3. sudo apt-get 安装 docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

相关内容