0

I try to extend the pytorch docker image with my definition file nnunet.def:

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..."

However, when I build this image (with sudo singularity build image.sif nnunet.def) I get the an error saying pip is not found:

...
+ 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

Why?

What is even more surprising is that when I enter in a shell directly from this image: singularity shell docker://pytorch/pytorch:1.4-cuda10.1-cudnn7-runtime

I have no problem using pip:

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

Why can't I use pip in the %post section of my definition file?

arthur.sw
  • 11,052
  • 9
  • 47
  • 104

1 Answers1

1

Short answer: the value of $PATH in %post is different from when you're running in shell, so it doesn't know where to look.

If you look at where pip is located (which pip) in either the docker or singularity image, it is at /opt/conda/bin/pip. The default path used in %post is /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin.

When you see an error stating that a command is not available when run as part of a script but it is when you run interactively, it is almost always an environmental issue and PATH, PYTHONPATH, PERL5LIB, etc. are the frequent culprits.

If you add export PATH=/opt/conda/bin:$PATH to the beginning of the %post block it should solve this issue.

tsnowlan
  • 3,472
  • 10
  • 15