【ubuntu20.04】报错Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?,卸载重装docker

1、起因

    虚拟机内的docker起不来了, 百度各种查,还是没解决(百度真拉胯),无奈测试需要用, 还是得折腾一下

 

2、清理docker容器及镜像(报错的话, 相关可能执行不了)

1、删除容器
1)首先需要停止所有的容器
docker stop $(docker ps -a -q)
2)删除所有的容器(只删除单个时把后面的变量改为image id即可)
docker rm $(docker ps -a -q)
2、删除镜像 1)查看host中的镜像 docker images 2)删除指定id的镜像 docker rmi image id 想要删除untagged images,也就是那些id为的image的话可以用 docker rmi $(docker images | grep “^” | awk “{print $3}”)

3)删除全部的images docker rmi $(docker images -q) 3、当要删除的iamges和其他的镜像有关联而无法删除时 可通过 -f 参数强制删除 docker rmi -f $(docker images -q)

 

3、卸载

sudo apt-get remove docker docker-engine docker.io docker-ce
sudo apt-get purge docker-engine
sudo apt-get autoremove –purge docker-engine
rm -rf /var/lib/docker

 

4、重装

更新源
sudo apt update

安装 docker.io
sudo apt install docker.io

安装报错

docker.io : Depends: containerd (>= 1.2.6-0ubuntu1~)

可能和update有关, 我是直接忽略

 

 

5、安装docker-ce

sudo apt-get install docker-ce

 

6、检查

master@master:~$ docker -v
Docker version 20.10.17, build 100c701
master@master:~$ docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
master@master:~$ docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

 

7、安装过程

master@master:~$ docker stop $(docker ps -a -q)
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
"docker stop" requires at least 1 argument.
See 'docker stop --help'.

Usage:  docker stop [OPTIONS] CONTAINER [CONTAINER...]

Stop one or more running containers
master@master:~$ docker ps -a -q
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
master@master:~$ sudo docker ps -a -q
[sudo] password for master: 
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
master@master:~$ docker images
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
master@master:~$ sudo apt-get remove docker docker-engine docker.io docker-ce Reading package lists... Done Building dependency tree Reading state information... Done Package 'docker-engine' is not installed, so not removed Package 'docker' is not installed, so not removed Package 'docker.io' is not installed, so not removed The following packages were automatically installed and are no longer required: docker-ce-rootless-extras pigz Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: docker-ce 0 upgraded, 0 newly installed, 1 to remove and 67 not upgraded. 1 not fully installed or removed. After this operation, 100 MB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 297579 files and directories currently installed.) Removing docker-ce (5:20.10.17~3-0~ubuntu-bionic) ...
master@master:
~$ sudo apt autoremove Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: docker-ce-rootless-extras pigz 0 upgraded, 0 newly installed, 2 to remove and 67 not upgraded. After this operation, 20.7 MB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 297571 files and directories currently installed.) Removing docker-ce-rootless-extras (5:20.10.17~3-0~ubuntu-bionic) ... Removing pigz (2.4-1) ... Processing triggers for man-db (2.9.1-1) ...
master@master:
~$ sudo apt-get purge docker-engine Reading package lists... Done Building dependency tree Reading state information... Done Package 'docker-engine' is not installed, so not removed 0 upgraded, 0 newly installed, 0 to remove and 67 not upgraded. master@master:~$ sudo apt-get autoremove –purge docker-engine Reading package lists... Done Building dependency tree Reading state information... Done Package 'docker-engine' is not installed, so not removed E: Unable to locate package –purge
master@master:
~$ sudo rm -rf /var/lib/docker
master@master:
~$ sudo apt update Hit:1 http://mirrors.aliyun.com/ubuntu focal InRelease Get:2 http://mirrors.aliyun.com/ubuntu focal-updates InRelease [114 kB] Get:3 http://mirrors.aliyun.com/ubuntu focal-backports InRelease [108 kB] Get:4 http://mirrors.aliyun.com/ubuntu focal-security InRelease [114 kB] Hit:5 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic InRelease Hit:6 https://dl.google.com/linux/chrome/deb stable InRelease Get:7 http://mirrors.aliyun.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [278 kB] Get:8 http://mirrors.aliyun.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [391 kB] Get:9 http://mirrors.aliyun.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [944 B] Get:10 http://mirrors.aliyun.com/ubuntu focal-backports/main amd64 DEP-11 Metadata [8,004 B] Get:11 http://mirrors.aliyun.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [30.5 kB] Get:12 http://mirrors.aliyun.com/ubuntu focal-security/main amd64 DEP-11 Metadata [40.7 kB] Get:13 http://mirrors.aliyun.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [66.6 kB] Get:14 http://mirrors.aliyun.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B] Fetched 1,154 kB in 12s (100 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done 67 packages can be upgraded. Run 'apt list --upgradable' to see them.
master@master:
~$ sudo apt install docker.io Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: docker.io : Depends: containerd (>= 1.2.6-0ubuntu1~) E: Unable to correct problems, you have held broken packages. master@master:~$ sudo apt-get install docker-ce Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: docker-ce-rootless-extras pigz slirp4netns Suggested packages: aufs-tools cgroupfs-mount | cgroup-lite The following NEW packages will be installed: docker-ce docker-ce-rootless-extras pigz slirp4netns 0 upgraded, 4 newly installed, 0 to remove and 67 not upgraded. Need to get 29.3 MB of archives. After this operation, 121 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://mirrors.aliyun.com/ubuntu focal/universe amd64 pigz amd64 2.4-1 [57.4 kB] Get:2 http://mirrors.aliyun.com/ubuntu focal/universe amd64 slirp4netns amd64 0.4.3-1 [74.3 kB] Get:3 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 docker-ce amd64 5:20.10.17~3-0~ubuntu-bionic [21.0 MB] Get:4 https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 docker-ce-rootless-extras amd64 5:20.10.17~3-0~ubuntu-bionic [8,163 kB] Fetched 29.3 MB in 12s (2,456 kB/s) Selecting previously unselected package pigz. (Reading database ... 297559 files and directories currently installed.) Preparing to unpack .../archives/pigz_2.4-1_amd64.deb ... Unpacking pigz (2.4-1) ... Selecting previously unselected package docker-ce. Preparing to unpack .../docker-ce_5%3a20.10.17~3-0~ubuntu-bionic_amd64.deb ... Unpacking docker-ce (5:20.10.17~3-0~ubuntu-bionic) ... Selecting previously unselected package docker-ce-rootless-extras. Preparing to unpack .../docker-ce-rootless-extras_5%3a20.10.17~3-0~ubuntu-bionic_amd64.deb ... Unpacking docker-ce-rootless-extras (5:20.10.17~3-0~ubuntu-bionic) ... Selecting previously unselected package slirp4netns. Preparing to unpack .../slirp4netns_0.4.3-1_amd64.deb ... Unpacking slirp4netns (0.4.3-1) ... Setting up slirp4netns (0.4.3-1) ... Setting up docker-ce (5:20.10.17~3-0~ubuntu-bionic) ... Setting up pigz (2.4-1) ... Setting up docker-ce-rootless-extras (5:20.10.17~3-0~ubuntu-bionic) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for systemd (245.4-4ubuntu3.17) ...
master@master:
~$ docker -v Docker version 20.10.17, build 100c701 master@master:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES master@master:~$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE

 

 

参考链接:

https://askubuntu.com/questions/1273024/docker-io-depends-containerd-1-2-6-0ubuntu1

https://blog.csdn.net/weixin_40098405/article/details/108200807

 

posted @ 2022-08-10 11:15  代码诠释的世界  阅读(1456)  评论(0编辑  收藏  举报