Skip to content

BuildFromConda

MatthewHiggins2017 edited this page Oct 23, 2023 · 1 revision

Singularity build from Conda

conda create --name YACRD -c yacrd minimap2=2.18

conda env export --no-builds -n YACRD > YACRD.yml

Create definition file, whereby the post command creates the environment from yml file. In addition, as the shell in singularity runs in a special environment, the standard conda modifications to the .bashrc do not work. Instead, you need to modify the $SINGULARITY_ENVIRONMENT variable to enable use to access the conda environment when running / executing commands on the container.

The YACRD.def file is shown below:

Bootstrap: docker

From: continuumio/miniconda3

%files
    YACRD.yml

%post
    /opt/conda/bin/conda env create -f YACRD.yml
    echo ". /opt/conda/etc/profile.d/conda.sh" >> $SINGULARITY_ENVIRONMENT
    echo "conda activate YACRD" >> $SINGULARITY_ENVIRONMENT
    


%runscript
    minimap2 --version

Now the definition file is created we can build the singularity container.

sudo singularity build YACRD_SI_v0.0.1.sif YACRD.def

To test if the singularity container is working run the following command. From the runscript we see that this should simply print the version of minimap2 which yacrd is dependent on e.g. minimap2 version 2.18

singularity run  YACRD_SI_v0.0.1.sif

To execute full commands using the container we can used the singularity exec command.

singularity exec YACRD_SI_v0.0.1.sif 'minimap2'

Note: As the container is already a SIF file it is production ready however if we did want to make any changes we could convert it to a sandbox version using the build command.

Clone this wiki locally