Containerize a conda environment in a Singularity container

纵然是瞬间 提交于 2019-11-29 10:17:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!