如何处理此 docker 安装后脚本错误?`mv: 无法统计'/var/lib/docker'`

如何处理此 docker 安装后脚本错误?`mv: 无法统计'/var/lib/docker'`

我尝试升级 docker,但收到错误,因此我重新安装。但是问题仍然存在。它无法显示的文件夹确实不存在。我该怎么做才能解决这个问题?

我当然可以简单地创建该目录并希望这不是某个东西严重损坏的迹象,以后会困扰我。但我希望得到比我更了解的人的意见。

generic@motorbrot:~$ sudo apt-get install docker.io
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  aufs-tools btrfs-progs debootstrap docker-doc rinse zfs-fuse | zfsutils
The following NEW packages will be installed:
  docker.io
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/36.9 MB of archives.
After this operation, 192 MB of additional disk space will be used.
Preconfiguring packages ...
Selecting previously unselected package docker.io.
(Reading database ... 539898 files and directories currently installed.)
Preparing to unpack .../docker.io_20.10.2-0ubuntu1~18.04.2_amd64.deb ...
Unpacking docker.io (20.10.2-0ubuntu1~18.04.2) ...
Setting up docker.io (20.10.2-0ubuntu1~18.04.2) ...
mv: cannot stat '/var/lib/docker': No such file or directory
dpkg: error processing package docker.io (--configure):
 installed docker.io package post-installation script subprocess returned error exit status 1
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Errors were encountered while processing:
 docker.io
E: Sub-process /usr/bin/dpkg returned an error code (1)

Docker 似乎已安装:

generic@motorbrot:~$ which docker
/usr/bin/docker
generic@motorbrot:~$ docker --version
Docker version 20.10.2, build 20.10.2-0ubuntu1~18.04.2

但当我运行时,sudo apt upgrade它显示为“未完全安装或删除”。

generic@motorbrot:~$ sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up docker.io (20.10.2-0ubuntu1~18.04.2) ...
mv: cannot stat '/var/lib/docker': No such file or directory
dpkg: error processing package docker.io (--configure):
 installed docker.io package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 docker.io
E: Sub-process /usr/bin/dpkg returned an error code (1)
generic@motorbrot:~/algolab$ dpkg -s docker.io | grep Status
Status: install ok half-configured

系统

我在 Ubuntu 18.04

$ uname -a
Linux motorbrot 5.4.0-72-generic #80~18.04.1-Ubuntu SMP Mon Apr 12 23:26:25 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

尝试使用 docker

但我无法启动守护进程。它说它被“屏蔽”了。

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
generic@motorbrot:~/algolab$ sudo systemctl docker start
Unknown operation docker.
generic@motorbrot:~/algolab$ sudo service docker start
Failed to start docker.service: Unit docker.service is masked.
generic@motorbrot:~/algolab$ sudo systemctl unmask docker
Removed /etc/systemd/system/docker.service.
generic@motorbrot:~/algolab$ sudo systemctl start docker
Failed to start docker.service: Unit docker.socket is masked.

创建目录/var/lib/docker

我尝试创建该目录,但无法统计(在创建 zfs 快照之后,以便在最坏的情况下可以回滚)。现在它抱怨它docker.migrating/docker不是空的。

generic@motorbrot:~$ sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up docker.io (20.10.2-0ubuntu1~18.04.2) ...
mv: cannot move '/var/lib/docker' to '/var/lib/docker.migrating/docker': Directory not empty
dpkg: error processing package docker.io (--configure):
 installed docker.io package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 docker.io
E: Sub-process /usr/bin/dpkg returned an error code (1)

即使我删除了该目录,仍然会遇到问题:

generic@motorbrot:~$ sudo rm -r /var/lib/docker.migrating/docker
generic@motorbrot:~$ sudo mkdir /var/lib/docker
generic@motorbrot:~$ sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Y
Setting up docker.io (20.10.2-0ubuntu1~18.04.2) ...
mv: target '/var/lib/docker/' is not a directory
dpkg: error processing package docker.io (--configure):
 installed docker.io package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 docker.io
E: Sub-process /usr/bin/dpkg returned an error code (1)

安装后脚本

/var/lib/dpkg/info/docker.io.postinst位于这个答案,在我看来,即使我提前创建了该目录,它也会删除该目录,然后抱怨它不存在。

快速浏览一下就会发现它对 ZFS 进行了特殊处理,所以我应该指出我确实在 root 权限下在 ZFS 上运行。

公寓清除

我现在有点疯狂了,反正我很少使用docker。我已经删除了所有让我烦恼的docker数据集zfs list

for dataset in $(zfs list | grep legacy | cut -f1); do zfs destroy -R "$dataset" || true ; done

并进行了清除

$ sudo apt purge docker.io

generic@motorbrot:~$ sudo apt purge docker.io
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  bridge-utils cgroupfs-mount containerd pigz runc ubuntu-fan
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  docker.io*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 192 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 540125 files and directories currently installed.)
Removing docker.io (20.10.2-0ubuntu1~18.04.2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
(Reading database ... 539920 files and directories currently installed.)
Purging configuration files for docker.io (20.10.2-0ubuntu1~18.04.2) ...
dpkg: warning: while removing docker.io, directory '/etc/docker' not empty so not removed

剩下一个文件/etc/docker/key.json

再次重新安装,得到新的问题:

generic@motorbrot:~$ sudo apt install docker.io
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Suggested packages:
  aufs-tools btrfs-progs debootstrap docker-doc rinse zfs-fuse | zfsutils
The following NEW packages will be installed:
  docker.io
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/36.9 MB of archives.
After this operation, 192 MB of additional disk space will be used.
Preconfiguring packages ...
Selecting previously unselected package docker.io.
(Reading database ... 539920 files and directories currently installed.)
Preparing to unpack .../docker.io_20.10.2-0ubuntu1~18.04.2_amd64.deb ...
Unpacking docker.io (20.10.2-0ubuntu1~18.04.2) ...
Setting up docker.io (20.10.2-0ubuntu1~18.04.2) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.
invoke-rc.d: initscript docker, action "start" failed.
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Fri 2021-04-23 14:31:06 CEST; 3ms ago
     Docs: https://docs.docker.com
  Process: 32306 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
 Main PID: 32306 (code=exited, status=1/FAILURE)
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
generic@motorbrot:~$ sudo systemctl restart docker

答案1

我粗心地搞砸了这件事,现在 docker 又能为我工作了!请注意,我的方法相当极端!

  • sudo apt remove docker.io
  • sudo apt purge docker.io
  • 如果/var/lib/docker/var/lib/docker.migating仍然存在,则删除它们
  • 如果zfs list | grep legacy显示任何 docker 数据集,请使用 将其全部删除。for dataset in $(zfs list | grep legacy | cut -f1); do zfs destroy -R "$dataset" || true ; done 同样,这是一个危险的命令,还可能破坏其他东西!确保您不关心数据丢失或知道自己在做什么。我甚至不知道是否需要这一步。
  • sudo apt install docker.io--> 收到错误
  • sudo systemctl restart docker

现在它又能为我工作了。

相关内容