问题描述
在使用 Docker 守护进程时,出现如下报错:
1 | [root@localhost ~]# docker restart -t1 tools-nginx-1 |
尝试解决
先检查了一下containerd
的状态,看了下是异常了,目前退出代码为2
1 | [root@localhost ~]# systemctl status containerd |
尝试重启一下containerd
服务:
1 | [root@localhost ~]# systemctl restart containerd |
但是并没有卵用,还是没能起来,尝试下其他办法,尝试了一下查看错误日志,如下:
1 | journalctl -u containerd -n 50 --no-pager |
1 | -- Logs begin at Sun 2024-12-22 17:12:15 CST, end at Sun 2024-12-22 18:40:57 CST. -- |
确定故障原因
上面看到有一个错误,panic: invalid page type: 2: 10
应该是由于数据库文件损坏导致的。
那么可以尝试一下删除数据库文件并且重建后再启动containerd
试试。
请注意,删除前强烈建议备份一下,这是好习惯,给自己一个补救的机会!
1 | cp -r /var/lib/containerd /var/lib/containerd.bak |
然后直接删除数据库文件:
1 | rm -rf /var/lib/containerd/* |
然后我们重启下containerd
服务:
1 | systemctl restart containerd |
重启完成后,再查看一下containerd
服务状态:
1 | [root@localhost ~]# systemctl status containerd |
可以看到containerd
服务已经正常启动了。
验证解决方案
我们再试试重启容器:
1 | [root@localhost ~]# docker restart -t1 tools-nginx-1 |
可以看到容器已经重启成功,那么至此 containerd
服务异常的问题就解决了,得出结论,数据库文件损坏导致的containerd
服务异常,可以尝试删除数据库文件,重建后再启动containerd
服务。