从现有docker映像扩展奇点映像的问题

问题描述

我尝试用定义文件nnunet.def扩展pytorch docker image

Bootstrap: docker
From: pytorch/pytorch:1.4-cuda10.1-cudnn7-runtime

%post
    git clone https://github.com/NVIDIA/apex
    cd apex
    pip install -v --no-cache-dir ./

%runscript
    echo "Running nnunet container..."

但是,当我使用sudo singularity build image.sif nnunet.def构建此图像时,出现一个错误,提示未找到pip:

...
+ pip install -v --no-cache-dir ./
/.build-script-post: 6: /.build-script-post: pip: not found
FATAL:   failed to execute %post proc: exit status 127
FATAL:   While performing build: while running engine: while running /usr/local/libexec/singularity/bin/starter: exit status 255

为什么?

更令人惊讶的是,当我直接从该图像输入外壳程序时: singularity shell docker://pytorch/pytorch:1.4-cuda10.1-cudnn7-runtime

我使用pip没问题:

Singularity> pip freeze
asn1crypto==1.2.0
backcall==0.1.0
...

为什么我不能在定义文件的%post部分中使用pip?

解决方法

简短的回答:$PATH%post的值与您在shell中运行时的值不同,因此它不知道在哪里查看。

如果您查看docker或奇异映像中pip的位置(which pip),则它位于/opt/conda/bin/pip%post中使用的默认路径为/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

当您看到一条错误消息,指出作为脚本的一部分运行时命令不可用,而当您以交互方式运行时,则几乎总是环境问题,PATHPYTHONPATHPERL5LIB等是罪魁祸首。

如果将export PATH=/opt/conda/bin:$PATH添加到%post块的开头,它将解决此问题。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...