What is Singularity
Singularity  is a container system that doesn't need root access. Containers are a set of applications and a minimal operating system bundled together in a single file. They are a good way to ensure that anyone running the software is using the exact same set of libraries and dependencies. This is helpful to reproducible science where we want somebody else to be able to recreate our results. They also allow us to run newer*/different operating systems than what is installed on the HPC.
Singularity has now been renamed apptainer, but the singularity program is still available if you load the apptainer module.
Run the command (or add it to your submission script):
module load apptainer
Singularity Hub  contains a number of premade containers which you can download and use. To download these run:
singularity pull shub://<username>/<imagename>:<tag>
singularity pull shub://SupercomputingWales/singularity_hub:base_image
This will then download the file to <username>-singularity_hub-master-<image name>.simg
Running a shell in a container
The singularity shell command will run a shell inside the container. You can then execute any commands from software installed in the container. To do this run the command "singularity shell".
singularity shell <image name>
singularity shell SupercomputingWales-singularity_hub-master-base_image.simg
Running the container's default actions
Most containers specify a default command which they will run. The "singularity run" command will execute this.
singularity run <image name>
Accessing the host file system from inside the container
singularity shell -B /ibers/ernie/home:/home <imagename>
This will mount the directory /ibers/ernie/home from the host under /home in the container. Your own home directory will be under /home/<userid>. Note that accessing the ~ or ~<userid> directories won't work.
Writing your own containers
To make your own containers you'll probably have to install singularity on your own computer, as building a container requires root access.
This example takes an ubuntu 16.04 image as a base, then installs the program cowsay. This is done when the container is built. When the container is run it executes cowsay with the arguments given on the command line.
bootstrap: docker From:ubuntu:16.04
%help Example container for Cowsay
%labels MAINTAINER IBERS Admin
%environment #configure our locale, without this we'll get locale errors export LC_ALL=C #cowsay installs to /usr/games, but this isn't in the path by default export PATH=/usr/games:$PATH %post apt-get update apt-get -y install cowsay
%runscript cowsay $@
To build the container save the above example in a file called Singularity and run:
sudo singularity build cowsay.simg Singularity
This will create an image file called cowsay.simg containing all the required software to run cowsay in an ubuntu 16.04 operating system.
Publishing a Container
- Publish the Singularity file on Github.
- Create an account on Singularity Hub.
- Add this repository to Singularity Hub and it will be automatically built by singularity hub and made available for download using the singularity pull command.
- Presentation on containers from the July 2018 Bioinformatics workshop.
- Official Documentation