问题
I've come across several instances where it would be really helpful to containerize a conda environment for long-term reproducibility. As I'm normally running in high-performance computing systems, they need to be Singularity containers for security reasons. How can this be done?
回答1:
First, you'll want to get the environment YML for your particular conda environment.
conda activate your_env
conda env export > environment.yml
Normally, you would just use this as follows:
conda env create -f environment.yml
But, it's slightly more involved to containerize your build with Singularity.
Here's an example Singularity recipe (in file named 'Singularity' in same directory as 'environment.yml'):
Bootstrap: docker
From: continuumio/miniconda3
%files
environment.yml
%environment
PATH=/opt/conda/envs/$(head -1 environment.yml | cut -d' ' -f2)/bin:$PATH
%post
echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc
echo "source activate $(head -1 environment.yml | cut -d' ' -f2)" > ~/.bashrc
/opt/conda/bin/conda env create -f environment.yml
%runscript
exec "$@"
Build this with
sudo singularity build conda.simg Singularity
Now, you'll have a functioning container using libraries from your conda environment that can be run anywhere you have Singularity installed!
Examples:
singularity run conda.simg conda -h
singularity run conda.simg ipython
来源:https://stackoverflow.com/questions/54678805/containerize-a-conda-environment-in-a-singularity-container