Singularity

Singularity

Singularity is a container platform that allows for the creation and running of containers from reproducible images. Singularity was designed for HPC in a way that is simpler and more portable than Docker and other container management platforms. Singularity avoids many of the security and reproducibility issues that come with docker, allowing for a more streamlined container environment on our clusters.
For more detailed information on Singularity, see sylab’s website or their documentation for version 3.7.
The process of Singularity Images: Pulling-> Building-> Running/Interacting

Loading the module

To load singularity into your environment, use the command
module load singularity

Pulling images

For Singularity images: singularity pull library://{image name}
Example: singularity pull library://lolcow
For Docker Images: singularity pull docker://{user}/{image name}
Example: singularity pull docker://godlovedc/lolcow

Building images

For Singularity images: singularity build {container name>}.sif library://{image name}
Example: singularity build ubuntu.sif library://ubuntu
For Docker images: singularity build {container name}.sif docker://{user}/{image name}
Example: singularity build lolcow.sif docker://godlovedc/lolcow

Interacting with container

To use the singularity image as a virtual machine use the shell command. This is useful if you are sshing into a node (ssh node{number}) and running the image there.
singularity shell {container name}.sif
Check that the command is successful and you are actually in the environment before running tasks.

Running the container

Runscripts are scripts defined by the user and specify the commands that should be executed when it’s run. If you are familiar with Dockerfiles it is similar to how those behave.
singularity run {container_name}.sif
Example: singularity run lolcow_latest.sif
Or you could run it just like you would an executable by doing ./{container name}

Mounting directories

By default, singularity will mount to the current directory (pwd), /home/$USER, and /tmp directories. However, you are able to add more directories with the --bind flag.
singularity exec --bind /data:/{directory path} {image name}.sif cat /mnt/{file}
Example:singularity exec --bind /data:/mnt lolcow_latest.sif cat /mnt/cow_advice.txt

Converting Docker images

Run the command docker images to view all docker images that have been pulled. Find the IMAGE ID of the image you want. We will use this in the docker save command.
docker save {IMAGE ID} -o {container name}.tar
We will then use singularity build on the docker archive:
singularity build –sandbox {container name} docker-archive://{path to tar file}
Now use the run commands above on you converted container!
Example: singularity build --sandbox lolcow docker-archive://lolcow.tar

Where to find images

Sylabs Cloud or Datalad
On the Sylabs Cloud website you are able to build your own image in the cloud, check image signatures, and share them to reproduce that image elsewhere.
Find images from the command line with singularity search {image name}