Olivier Kirsh :
olivier.kirsh@u-paris.fr
This page summarize some usefull infomations to get started with Singularity/Apptainer containers.
This tuto also works on win10 thanx to WSL. I haven't done any test on macOS.
-
Get WSL (Windows Subsystem for Linux) from the microsoft store if you aren't on a linux distribution.
-
Follow instructions from Apptainer The lines bellow works for my pc. Please read the doc, and adapt it to your setup.
- Install dependencies (kind of balck magics)
# Ensure repositories are up-to-date sudo apt-get update # Install debian packages for dependencies sudo apt-get install -y \ build-essential \ libseccomp-dev \ pkg-config \ squashfs-tools \ cryptsetup \ curl wget git
- remove any previous GO installations (Disclaimer: if you really want to)
sudo rm -rf /usr/local/go* && sudo rm -rf /usr/local/go- Install last GO version (check updates and personal setup)
VERSION=1.18 OS=linux ARCH=amd64 cd $HOME wget https://storage.googleapis.com/golang/go$VERSION.$OS-$ARCH.tar.gz tar -xvf go$VERSION.$OS-$ARCH.tar.gz mv go go-$VERSION sudo mv go-$VERSION /usr/local
- Update your .bashrc
export GOROOT=/usr/local/go-1.18 export GOPATH=$HOME/projects/go export GOBIN=$GOPATH/bin export PATH=$PATH:$GOROOT/bin export PATH=$PATH:$HOME/projects/go/bin
- Install last Singularity/Apptainer version
# get singularity/Apptainer export VERSION=1.0.0 && # adjust this as necessary \ wget https://github.com/apptainer/apptainer/releases/download/v${VERSION}/apptainer-${VERSION}.tar.gz && \ tar -xzf apptainer-${VERSION}.tar.gz && \ cd apptainer-${VERSION} # compile singularity ./mconfig && \ make -C builddir && \ sudo make -C builddir install
Here are usefull links to get familiar with Singularity
- Singularity at IFB, tuto and how to.
- Nebraska HCC ressources.
-
Version Control with Git SWC courses. Needed for many actions.
-
(re)découvrez Git en français.
-
Singularity Hub, now nammed datalad.
-
Singularity - old site, the new doc is at this url https://apptainer.org/docs.
-
Singularity Container Services, Sylabs documentation Docs (Sylabs).
-
Singularity Container Services, Sylabs user guide User guide (Sylabs).
-
Formation bash git singularity, lien vers TP (en français).
-
Créer un conteneur avec Singularity, TP Rémy Dernat.
-
How to build a Singularity container hands-on Martin Souchal.
-
Slides Tuto Singularity & Docker Martin Souchal, 2019...
-
Slides intro Singularity Cédric Clerget, 2016...
On 2022-09-05 the lastest Apptainer stable version is 1.1.0-rc.2.
The installed version on our clusters are :
[kirsh@ipop-up ~]$ singularity --version singularity version 3.8.5-2.el7
For more infos about the cluster, read the documentation
[okirsh@core-login1 ~]$ singularity --version singularity version 3.5.3
For more infos about the cluster, read the documentation
[kirsh@goliath ~]$ singularity --version
2.6.1-dist
RTFM for more details
You must be sudo !!
- from Sylab container library
sudo singularity build lolcow.simg library://sylabs-jms/testing/lolcow
- from shub (Singularity Hub archive)
sudo singularity build ngs2.simg shub://kirsho/ngs2
Note that shub is now read only. Alternative solutions are described here to share and distribute your Singularity image.
Actually there is large interoperability between Docker and Singularity. It's really easy to start from a Docker image to create a Singularity image. Details here.
- from docker Hub
sudo singularity build ngs2.sif docker://genomicpariscentre/bowtie2
Like Docker with a docker file, you can build a Singularity image with a recipe (a definition file).
Note that you can run / execute a Singularity image without "creating" it before. the singularity exec (or pull or shell) will do it for you if you provide the right link to the repository.
But if you want to do it, the command is as simple as:
sudo singularity build myimage.simg myimage.def
Note that you can name your image as .simg or .sif
Note that you can name your definition file as .def or Singularity (needed when you want to deploy through shub, see further sections)
Again read the manual to understand file contents. Basically what it does is :
- calling a docker image with a linux/debian and miniconda already installed. More details here continuumio/miniconda3
- Set and add conda inthe PATH
- Create a conda env with my ngs tools env "ngs3"
Bootstrap: docker
From: continuumio/miniconda3
%files
ngs3.yml
%environment
PATH=/opt/conda/envs/$(head -1 ngs3.yml | cut -d' ' -f2)/bin:$PATH # Change $PATH
%post
echo "Creating a Singularity Container of my ngs3 Conda Env" # What I'm doing
echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc # enable conda for the current
echo "conda activate $(head -1 ngs3.yml | cut -d' ' -f2)" >> ~/.bashrc # will start "ngs3" conda env
apt-get update && apt-get -y install nano tree htop wget build-essential # Install some extras
/opt/conda/bin/conda update -n base -c defaults conda # Update Conda
/opt/conda/bin/conda env create -f ngs3.yml # Conda create my env
%runscript
exec "$@"
%labels
Maintainer olivier.kirsh@u-paris.fr
Version v1.0 20190701
- Create the Singularity image with :
sudo singularity build ngs3.simg ngs3.def
This github repository hosts my last version of my Singularity file.
This Singularity file as been used to test interoperability of conda envs between my local machine, ifb-nncr and RPBS cluster.
rst36-env github repository hosts :
- Singularity definition file for conda or yml environment creation
- an example of a yml file You can clone it to build and use this this env.
You can also see examples of definition files I use [here](https://github.com/kirsho/Singularity/tree/master/def]
Just send the .def file. Any user with Singularity installed in his machine can re-build the image.
Share the image. Quite stupid, could weight 1 Go at least. Share the def file instead. But can be easier if your collaborators do not handle Singularity
with singularity push.
Requires version > 3.0.1.
** this section must be updated since shub is now datalad.**
shub container registry It works with your github account
- login to github
- Create a new repository
- open a terminal and to your working folder containing the
def filenammedSingularityand type:
git init
git add Singularity
git commit -m "first commit"
git remote add origin https://github.com/kirsho/ngs2.git
git remote -v
git push origin master
shub will create the image. it can take few minutes.
How to use them is explained here
use git pull origin master --allow-unrelated-histories if you already have files in your remote repository.
The above image example include ngs tools 'insulated' in a conda environment. Conda is wonderfull since it allows the creation of separated envs where different versions of a software or incompatible application can coexist on a unique machine. Conda is also wonderfull because it allows easy installation of an application with all its dependencies, whatever your machine is.
This recipe works whatever the conda env is local or at IFB
- Open a terminal and load conda (via an alias in my bashrc, it's the way I configure it)
condainit
- Export conda env recipe in a yml file
conda env export --no-build -n ngs3 -f ~/whereyouwant/ngs3.yml
- Use this
.ymlin yourdef fileto build your image
- Login to ifbcore via ssh
ssh .....
- Explore available conda envs
conda env list
Last login: Wed Jul 3 10:28:18 2019 from edc95.sdv.univ-paris-diderot.fr
(base) [okirsh@clust-slurm-client ~]$ conda env list
# conda environments:
#
base * /shared/mfs/data/software/miniconda
bcftools-1.9 /shared/mfs/data/software/miniconda/envs/bcftools-1.9
bedtools-2.26.0 /shared/mfs/data/software/miniconda/envs/bedtools-2.26.0
bedtools-2.27.1 /shared/mfs/data/software/miniconda/envs/bedtools-2.27.1
biokevlar-0.6.1 /shared/mfs/data/software/miniconda/envs/biokevlar-0.6.1
blast-2.7.1 /shared/mfs/data/software/miniconda/envs/blast-2.7.1
bowtie-1.2.2 /shared/mfs/data/software/miniconda/envs/bowtie-1.2.2
...
...
- Export recipe of the env you want to "clone".
conda env export --no-build -n bowtie2-2.3.4.3 -f ~/whereyouwant/bw223.yml
- Bring it back to HOME
scp ....
- Use this
.ymlin yourdef fileto build your image
shell, run & execute are the three main singularity verbs
-
Use
singularity shell xxx.simgto get a shell in your image. -
Use
singularity run xxx.simg xxxx.shto run a script in your image. -
Use
singularity exec -B $PWD:/data shub://kirsho/bw223 bowtie2 --threads $SLURM_CPUS_PER_TASK -x mm10/mm10 $fq > ${fq/.fastq.gz/.sam}to run a program in your image on a cluster. This command is excuted from an sbatch file.
#!/bin/bash
#SBATCH --output=testbw223ifb-%j.out
#SBATCH --array=1-2
#SBATCH -p fast
#SBATCH --job-name=singbw2ifb
#SBATCH --cpus-per-task=12
#SBATCH --mail-user=olivier.kirsh@u-paris.fr
#SBATCH --mail-type=BEGIN
#SBATCH --mail-type=FAIL
#SBATCH --mail-type=END
case "$SLURM_ARRAY_TASK_ID" in
1) fq="ENCFF179JEC.fastq.gz"
;;
2) fq="ENCFF931IVO.fastq.gz"
;;
esac
singularity exec -B $PWD:/data shub://kirsho/bw223 bowtie2 --threads $SLURM_CPUS_PER_TASK -x mm10/mm10 $fq > ${fq/.fastq.gz/.sam}
Note that contrary to docker, Singularity image mount your current folder. You can change it name and path with -B $PWD:/data . In docker use -v $PWD:/data . this section deserve an update. Read here for more details.
Since the first version of this page (2019-07-03), some changes have occured.
Links and command have been updated on this page. Some broken url or depreciated commands may persist.
Singularity become Apptainer in may 2021.
Singularity 3.6.8 -> apptainer-1.0.0
New link to documentation and to Github
The singularity xxxx commands still work with Apptainer.
Conda -> Mamba
mamba added to conda locally and on my images via https://anaconda.org/conda-forge/mamba
Mamba is faster in dependencies solving durring conda environment creation. For more information on mamba, read the documentation on github.