首页
首页
文章目录
  1. 简介:
  2. 解决方法:

docker oci runtime error: exec failed: container_linux.go故障修复处理

简介:

公司机房断电,开发环境的一台机器docker挂了报错,执行docker exec 时提示“rpc error: code = 13 desc = invalid header field value “oci runtime error: exec failed: container_linux.go:247: starting container process caused "exec: \"bassh\": executable file not found in $PATH"\n””错误
docker_error_01

解决方法:

在google 之后找到了这篇文章https://phpor.net/blog/post/6142

docker玩的就是名字空间和cgroup,所以不能不想到这些;libcontainerd也有自己的(mnt)名字空间,我们进入libcontainerd进程的文件系统就可以查看到上面目录的存在了,而且,正常的容器存在相应的目录,异常的容器不存在相应的目录;

通过mount命令可以发现mount的规律,从容器的config.json (/var/run/docker/libcontainerd/c6176f37c4b67b03d4187edef6d1131cd44ab80bd0f0c20b24a7a20056967652/config.json) 中查看到对应的mount的位置,通过nsenter进入libcontainerd的mnt名字空间手动mount上去就好了
脚本如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
# author: phpor
#
LIBCONTAINERD_DIR=/var/run/docker/libcontainerd

function main() {
local pidOfCotainerd=$(pidof docker-containerd-current)
local mountinfo=$(< /proc/$pidOfCotainerd/mountinfo)
for config in $LIBCONTAINERD_DIR/*/config.json;do
local cid=$(awk -F'/' '{print $6}' <<<$config)
local rootpath=$(jq -r .root.path $config|sed 's/\/rootfs$//')
grep "$rootpath" <<<$mountinfo >/dev/null
if [[ $? -eq 0 ]]; then
echo $cid $rootpath OK
else
echo $cid $rootpath Should repair
local device=/dev/mapper/$(docker inspect $cid|jq -r .[0].GraphDriver.Data.DeviceName)
nsenter -m -p -t $pidOfCotainerd mount -t xfs -o rw,nouuid,attr2,inode64,sunit=512,swidth=1024,noquota $device $rootpath
fi
done
}
main

但是我在运行该脚本时报错,提示 jq命令不存在,jq命令是基于epel的所以需要先安装epel在安装jq即可

以下解决方法

1
2
3
4
https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
rpm -ivh epel-release-7-11.noarch.rpm
yum repolist
yum install jq -y

之后在运行上面的脚本即可

以上

End!

支持一下
扫一扫,我会更有动力更新
  • 微信扫一扫
  • 支付宝扫一扫