From MetaCentrum
Jump to: navigation, search
Singularity logo.svg

Singularity enables users to have full control of their environment. This means that a non-privileged user can “swap out” the operating system on the host for one they control. So if the host system is running RHEL6 but your application runs in Ubuntu, you can create an Ubuntu image, install your applications into that image, copy the image to another host, and run your application on that host in it’s native Ubuntu environment!


Singularity is installed on all MetaCentrum and Cerit nodes. You can also try experimental version from development branch available in /opt/singularity.

Basic usecases

Some basic usecases covering the singularity usage are bellow. Please note, that mentioning all nuances (especially usage of various versions of MPI or running parallel job on different infiniband HW) is beyond scope of this section.

Interactive session

[dexter@ungu1 ~]$ singularity shell my_image.img
Singularity: Invoking an interactive shell within container...

Running command

[dexter@ungu1 ~]$ singularity exec my_image.img bash -c "java -version"
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

PBS Pro: singularity interactive session

qsub -I -l select=1 -l walltime=24:00:00 -- /usr/bin/singularity shell my_image.img

PBS Pro: running script inside singularity container

qsub -l select=1 -l walltime=24:00:00 -- /usr/bin/singularity exec my_image.img bash -c "/path/to/"

PBS Pro: running parallel job using singularity

The scenario for this setup is: two nodes with common scratch dir

 #PBS -l select=2:ncpus=2:mem=1gb:scratch_shared=4gb
 #PBS -l walltime=04:00:00
 #PBS -l place=scatter
 # modify/delete the above given guidelines according to your job's needs

 module add openmpi-2.0.1-gcc
 cat $PBS_NODEFILE |uniq >nodes.txt

 # run job over ethernet or infiniband (mpirun autoselects better)
 mpirun -n 2 --hostfile nodes.txt singularity exec my_image.img /path/to/program

More information about parallelization and different setups (specially for programs supporting MPI and OpenMP together) can be found in How_to_compute/Parallelization.

Preparing your own singularity image

Preparing your own singularity image is intended for experienced users hence machine with root access is may be needed and reading singularity documentation singularity documentation is a good idea too :) In general, you do not need root privileges if you can (re)use existing docker image.

Without root privileges you can do simply:

singularity image.create -s size_in_mb image.img
singularity build image.img docker://tensorflow/tensorflow:latest

However, if you want to change something or make your own image from scratch, you'll need root privileges to be able to write (-w) into container image:

singularity image.create -s size_in_mb image.img
singularity build -w image.img docker://ubuntu:latest # build base image from Docker hub
singularity shell -w image.img
apt-get install my_software



Program administrator