OCI runtime create failed: container_linux.go:345: starting container process caused “exec: \“pip\“

OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"pip\": executable file not found in $PATH": unknown

Docker Dockerfile

Dockerfile 是一个用来构建镜像的文本文件,文本内容包含了一条条构建镜像所需的指令和说明。

本文在制作 BERT 文本分类模型镜像时,碰到的 docke build 的 pip 错误:
OCI runtime create failed: container_linux.go:345: starting container process caused “exec: “pip”: executable file not found in $PATH”: unknown

Dockefile 制作镜像

使用 pip 安装依赖包:

pip install -r  /home/bert_model/requirements.txt  -i  https://pypi.tuna.tsinghua.edu.cn/simple

写成 Dockefile 的命令:

RUN ["pip", "install", "-r", "/home/bert_model/requirements.txt", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple"]

Dockefile:

FROM refazul/python3.9.0

ADD bert_model.tar /home


RUN ["pip", "install", "-r", "/home/bert_model/requirements.txt", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple"]

ENTRYPOINT ["bash", "/home/bert_model/run.sh"]

创建镜像

docker build -t bert_model:v1 .

报错信息

详细报错信息如下:

OCI runtime create failed: container_linux.go:345: starting container process caused "exec: \"pip\": executable file not found in $PATH": unknown

解决方法

先创建测试容器

docker run -it -d \
    --name test_v2 \
    -v /bee/test_model/:/notebooks \
    -e TZ='Asia/Shanghai' \
    --shm-size 16G \
    refazul/python3.9.0:latest

再进入容器

docker exec -it test_v2  bash

查找 pip 路径

执行:

whereis pip

输出:

# whereis pip
pip: /root/.pyenv/shims/pip3.9 /root/.pyenv/shims/pip

可以看出 pip 不在默认的 $PATH 路径下面

修改 pip 路径

修改 Dockefile 中的 pip 命令

RUN ["pip", "install", "-r", "/home/bert_model/requirements.txt", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple"]

为:

RUN ["/root/.pyenv/shims/pip", "install", "-r", "/home/bert_model/requirements.txt", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple"]

Dockefile:

FROM refazul/python3.9.0

ADD bert_model.tar /home


RUN ["/root/.pyenv/shims/pip", "install", "-r", "/home/bert_model/requirements.txt", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple"]

ENTRYPOINT ["bash", "/home/bert_model/run.sh"]

再执行:

docker build -t bert_model:v1 .

执行成功,输出:

Removing intermediate container 214e6260dbca
 ---> 8052d3dacd3f
Step 4/4 : ENTRYPOINT ["bash", "/home/bert_model/run.sh"]
 ---> Running in b59877caf0fc
Removing intermediate container b59877caf0fc
 ---> fc79cd19acb5
Successfully built fc79cd19acb5
Successfully tagged bert_model:v1 

参考

  1. https://www.runoob.com/docker/docker-dockerfile.html
  2. https://blog.csdn.net/m0_48742971/article/details/122991481

猜你喜欢

转载自blog.csdn.net/zengNLP/article/details/132301078