I have the following Singularity container recipe:
#!/bin/bash
Bootstrap: docker
From: nipype/nipype:latest
%labels
Version v1.0
%post
# Install nano
apt-get update
apt-get install nano
# Set up Python environment
CONDA_ENV=/opt/conda/bin
export PATH=$CONDA_ENV:$PATH
chmod -R 777 $CONDA_ENV
# Activate conda environment
conda activate neuro
conda install seaborn
pip install pybids
and I build the container with Singularity as follows:
sudo singularity build swish.simg Singularity.swish
The install of dependencies and majority of build goes OK until I hit the error that source not found
. To reiterate the issue and what I've tried:
- I'm building a Nipype image from the recipe. Within %post, I'd like to install two additional packages (seaborn and pybids) into the "neuro" conda environment.
- However, when I try to activate the neuro environment within %post ("source activate neuro"), I keep getting an error message saying that the command "source" is not found.
- I'd like to run the commands in %post with bash, but am not sure where to specify it.
The issue comes down to the way you are activating the environment. Normally, you would do:
but in the case that the Singularity container post is building in a shell (sh) environment, the expectation is that you won't find the
source
command. Instead you want to do:and then you don't need to fuss with the
$PATH
. You also don't need to specify an interpreter at the top of the file. So the entire recipe should look like:And then usage would be:
I've put the entire record of this in a gist
Helpful Debugging Tips
Here are a few helpful debugging tips! The way I figured out the above was to do a build commenting out the last lines with conda that triggered the error. Then I could build a writable sandbox:
and shell in with writable. This wiil allow me to make changes and test.
Since the container would have writable, this means that changes would persist, so you can exit from being root, and then edit in user space to test if your root changes indeed fixed the issue!
Then when you think all is well, delete the image and build from scratch and test.