Docker 卸载 以及删除/var/lib/docker报错:Device or resource busy

  1. 删除容器和镜像
docker rm-f $(docker ps -a -q)
docker rmi $(docker images -q)
  1. 停止docker服务
systemctl stop docker
  1. 删除docker相关存储目录
rm -rf /etc/docker
rm -rf /run/docker
rm -rf /var/lib/dockershim

# 容器与镜像存放在此目录
rm -rf /var/lib/docker 
  1. 删除/var/lib/docker目录报错
    rm"/var/lib/docker/containers/caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8/secrets":Device or resource busy
    说明/var/lib/docker目录下,有挂载目录, 找到挂载目录的位置
cat /proc/mounts |grep "docker" |grep "caf8ef20f3c1

然后取消挂载后

umount /data/sys/var/docker/containers/caf8ef20f3c1c78f03a5844ee23abc1d7e44246f242292040f1ef288899d0cb8/secrets

然后再执行

rm -rf /var/lib/docker 

接下来分两种情况:

  • docker是离线,手动导入, 需要删除bin目录下文件以及docker.service
for i in ("containerd"  "containerd-shim" "containerd-shim-runc-v2"  "ctr"  "docker"  "dockerd"  "docker-init"  "docker-proxy"  "runc")
do
rm -f /usr/bin/$i
done

rm -f /etc/systemd/system/docker.service
  • yum源安装的docker
  1. 查看安装的docker包

[root@ecs-46078391 ~]# yum list installed | grep docker
containerd.io.x86_64                  1.6.8-3.1.el7                   @docker-ce-stable
docker-ce.x86_64                      3:20.10.9-3.el7                 @/docker-ce-20.10.9-3.el7.x86_64
docker-ce-cli.x86_64                  1:20.10.17-3.el7                @docker-ce-stable
docker-ce-rootless-extras.x86_64      20.10.17-3.el7                  @docker-ce-stable
docker-scan-plugin.x86_64             0.17.0-3.el7                    @docker-ce-stable

  1. 卸载相关包
yum remove containerd.io.x86_64 docker-ce.x86_64 docker-ce-cli.x86_64 docker-ce-rootless-extras.x86_64 docker-scan-plugin.x86_64
  1. 出现选择提示,直接输入“y”然后回车
  2. 再次查看安装的包,并测试docker命令
yum list installed | grep docker
docker version

你可能感兴趣的:(docker,docker,容器,运维)