在单一容器中将conda环境容器化 [英] Containerize a conda environment in a Singularity container
问题描述
我遇到过许多实例,将conda环境容器化以实现长期可重复性确实很有帮助。由于我通常在高性能计算系统中运行,因此出于安全考虑,它们必须是奇异容器。
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?
推荐答案
首先,您需要为特定的conda环境获取环境YML。
First, you'll want to get the environment YML for your particular conda environment.
conda activate your_env
conda env export > environment.yml
以下是示例奇点配方(在与环境相同目录中名为奇点的文件中.yml'):
Here's an example Singularity recipe (in file named 'Singularity' in same directory as 'environment.yml'):
Bootstrap: docker
From: continuumio/miniconda3
%files
environment.yml
%post
/opt/conda/bin/conda env create -f environment.yml
%runscript
exec /opt/conda/envs/$(head -n 1 environment.yml | cut -f 2 -d ' ')/bin/"$@"
使用
sudo singularity build conda.sif Singularity
现在,您将可以使用conda环境中的库来运行一个可运行的容器任何安装了奇点的地方!
Now, you'll have a functioning container using libraries from your conda environment that can be run anywhere you have Singularity installed!
示例:
singularity run conda.sif ipython
注意:
取决于奇点版本正在使用,您可能需要用您的环境名称更改$(head -n 1 environment.yml | cut -f 2 -d'')。
Depending on the version of Singularity you're using, you may need to alter $(head -n 1 environment.yml | cut -f 2 -d ' ') with the name of your environment.
由于无法从运行脚本激活环境,因此只能使用提供的运行脚本来限制安装在特定环境中的二进制文件。
Since you can't activate the environment from the runscript, you'll be restricted to binaries installed in your particular environment with the provided runscript.
这篇关于在单一容器中将conda环境容器化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!