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-perf
I have found it useful because you can have a container with anaconda3 environment installed and easily create new Environments for your different projects whenever you want.
This is simple and I will go over it step by step:
Create the container in your local machine by the following definition file (you can name it whatever you want. Note that some lines might be avoidable ):
Bootstrap: library
From: ubuntu:18.04
Stage: build
%post
apt-get update && apt-get -y upgrade
apt-get -y install \
build-essential \
wget \
bzip2 \
ca-certificates \
libglib2.0-0 \
libxext6 \
libsm6 \
libxrender1 \
git
rm -rf /var/lib/apt/lists/*
apt-get clean
#Installing Anaconda 3
wget -c https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh
/bin/bash Anaconda3-2020.02-Linux-x86_64.sh -bfp /usr/local
#Conda configuration of channels from .condarc file
conda config --file /.condarc --add channels defaults
conda config --file /.condarc --add channels conda-forge
conda update conda
#List installed environments
conda list
Then, in order to build the container, run the following commands:
sudo singularity build ContainerName.sif YourDefineFile.def
Now you can create your conda env(you can use common ways or create it by YML file which is an exported file from an existing environment)
For example, I did it with a YML file: First, you need to get into your .sif container as following:
Singularity shell YourContainerName.sif
And then:
conda env create --name envname --file=YourEnvironments.yml
Therefore, After your env is created, you can activate it with the following commands(again first you need to jump into your container):
singularity shell YourContainer.Sif
source activate YourEnvName