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
使用 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
执行:
whereis pip
输出:
# whereis pip
pip: /root/.pyenv/shims/pip3.9 /root/.pyenv/shims/pip
可以看出 pip 不在默认的 $PATH 路径下面
修改 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