在使用docker images 时报如下错误:
$ docker images
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
遂尝试启动docker服务使用命令如下:
$ systemctl start docker
Failed to start docker.service: Unit docker.service is masked.
遂尝试使用如下命令去解决:
$ systemctl unmask docker.service
Removed /etc/systemd/system/docker.service.
$ systemctl unmask docker.socket
Removed /etc/systemd/system/docker.socket.
# 使用如下命令再次尝试重启,仍报错
$ systemctl start docker.service
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.
遂使用提示的命令继续查看详细的错误信息:
$ systemctl status docker.service
● docker.service - LSB: Create lightweight, portable, self-sufficient containers.
Loaded: loaded (/etc/init.d/docker; generated)
Active: failed (Result: exit-code) since Fri 2022-11-11 10:51:15 CST; 20s ago
Docs: man:systemd-sysv-generator(8)
Process: 765446 ExecStart=/etc/init.d/docker start (code=exited, status=1/FAILURE)
Main PID: 1829 (code=exited, status=0/SUCCESS)
Nov 11 10:51:15 m8-cbg-pbu-014300138096.ops.megvii-inc.com systemd[1]: Starting LSB: Create lightweight, portable, self-sufficient co
Nov 11 10:51:15 m8-cbg-pbu-014300138096.ops.megvii-inc.com docker[765446]: * /usr/bin/dockerd not present or not executable
Nov 11 10:51:15 m8-cbg-pbu-014300138096.ops.megvii-inc.com systemd[1]: docker.service: Control process exited, code=exited status=1
Nov 11 10:51:15 m8-cbg-pbu-014300138096.ops.megvii-inc.com systemd[1]: docker.service: Failed with result 'exit-code'.
Nov 11 10:51:15 m8-cbg-pbu-014300138096.ops.megvii-inc.com systemd[1]: Failed to start LSB: Create lightweight, portable, self-suffic
可以看到核心的错误就是下面的LSB 错误,按照Stack Overflow 上的方法,通过如下命令解决:
$ sudo apt remove docker && sudo apt install docker docker-ce
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'docker' is not installed, so not removed
The following packages were automatically installed and are no longer required:
aufs-tools cgroupfs-mount docker-ce-cli libltdl7
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 215 not upgraded.
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package docker-ce is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
docker-ce-cli
E: Package 'docker-ce' has no installation candidate
执行完后,再执行下面的命令:
$ wget -qO- https://get.docker.com/ | sh
# Executing docker install script, commit: 4f282167c425347a931ccfd95cc91fab041d414f
Warning: the "docker" command appears to already exist on this system.
If you already have Docker installed, this script can cause trouble, which is
why we're displaying this warning and provide the opportunity to cancel the
installation.
If you installed the current Docker package using this script and are using it
again to update Docker, you can safely ignore this message.
You may press Ctrl+C now to abort this script.
+ sleep 20
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sh -c mkdir -p /etc/apt/keyrings && chmod -R 0755 /etc/apt/keyrings
+ sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
+ sh -c chmod a+r /etc/apt/keyrings/docker.gpg
+ sh -c echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu bionic stable" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-scan-plugin >/dev/null
+ version_gte 20.10
+ [ -z ]
+ return 0
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce-rootless-extras >/dev/null
+ sh -c docker version
Client: Docker Engine - Community
Version: 20.10.21
API version: 1.41
Go version: go1.18.7
Git commit: baeda1f
Built: Tue Oct 25 18:02:00 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.21
API version: 1.41 (minimum version 1.12)
Go version: go1.18.7
Git commit: 3056208
Built: Tue Oct 25 17:59:53 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.9
GitCommit: 1c90a442489720eec95342e1789ee8a5e1b9536f
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
================================================================================
To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:
dockerd-rootless-setuptool.sh install
Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.
To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/
WARNING: Access to the remote API on a privileged Docker daemon is equivalent
to root access on the host. Refer to the 'Docker daemon attack surface'
documentation for details: https://docs.docker.com/go/attack-surface/
================================================================================
上面执行完后,docker 服务可正常使用了
网友评论