docker-compose exec时 出现"fork/exec /proc/self/exe: no such file or directory" 报错
问题:跟往常一样执行docker-compos exec redis sh时出现如下错误,而容器是运行状态中。
# docker-compose exec redis sh rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:247: starting container process caused "process_linux.go:75: starting setns process caused \"fork/exec /proc/self/exe: no such file or directory\""
解决办法:
1、获取容器ID
# docker ps | grep arcs_redis_1 ac248a3c5c0e redis:alpine "docker-entrypoint..." 2 years ago Up 16 minutes 6379/tcp arcs_redis_1
2、通过容器ID获取容器的PID
# ps -ef|grep libcontainerd | grep ac248a3c5c0e root 6650 9053 0 11:14 ? 00:00:00 docker-containerd-shim ac248a3c5c0e3f6405c35e186b5d095aeb7af72b0f52bb08303baded251cdb61 /var/run/docker/libcontainerd/ac248a3c5c0e3f6405c35e186b5d095aeb7af72b0f52bb08303baded251cdb61 docker-runc
注:第二个字段为容器的PID
3、获取容器的mount位置
# grep "path:" /var/run/docker/libcontainerd/ac248a3c5c0e3f6405c35e186b5d095aeb7af72b0f52bb08303baded251cdb61/config.json
注:mount的路径:{"path":"/var/lib/docker/devicemapper/mnt/cc2ff9576cdf7736acca50ffdaadef471e01a8ffe9acb039c1d423edd941bd38/rootfs"},此路径用于第6步挂载时使用。
4、用nsenter进入容器的namespace
# nsenter -m -t 6650 bash
注: 6650是容器的PID
5、查看容器的DeviceName
# docker inspect --format='{{.GraphDriver.Data.DeviceName}}' ac248a3c5c0e ####ac248a3c5c0e是容器ID
docker-252:0-9700888-cc2ff9576cdf7736acca50ffdaadef471e01a8ffe9acb039c1d423edd941bd38
6、手动挂载
# mount /dev/mapper/docker-252\:0-9700888-cc2ff9576cdf7736acca50ffdaadef471e01a8ffe9acb039c1d423edd941bd38 -o rw,relatime,nouuid,attr2,inode64,sunit=512,swidth=1024,noquota -t xfs /var/lib/docker/devicemapper/mnt/cc2ff9576cdf7736acca50ffdaadef471e01a8ffe9acb039c1d423edd941bd38
7、退出
#exit
8、再次执行docker-compose exec redis sh 无报错。
说明:此报错是由于mount挂载点丢失,具体原因目前还未知晓,若有知晓者欢迎告知!