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

2024-04-20 10:08:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用我的定义文件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


Tags: installpip文件dockerimagebuild定义def
1条回答
网友
1楼 · 发布于 2024-04-20 10:08:47

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

如果查看docker或singularity图像中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块的开头,应该可以解决此问题

相关问题 更多 >