Skip to content

Containerisation with Singularity

Singularity docs

This documentation page provides a brief overview of using Singularity on Baskerville, along with some specifics concerning its implementation. However, for further information please refer to the relevant version of the Sylabs Singularity official documentation.

Baskerville supports containerisation using Singularity. The singularity command is available on all nodes (although note the warning below regarding /tmp) and does not require the explicit loading of a corresponding module.

Pulling images and running containers

/tmp directory size

Due to the limited size of the /tmp directory on the Baskerville login nodes, please run all singularity pull commands inside Slurm jobs on the compute nodes. (We recommend using an Interactive Job to do this.)

To pull an image from the Sylabs Singularity Library:

singularity pull library://sylabsed/examples/lolcow

To pull an image from Docker Hub:

singularity pull docker://python
singularity pull docker://python:3.8.11  # pulls a specific tag

Two common methods for using a Singularity container are exec and shell:

  • singularity exec is for where you want to run a command in a container and then exit the container as soon as the command completes
  • singularity shell is for where you want to launch a container and then attach to its shell

An example of singularity exec:

singularity exec python_3.8.11.sif python --version

The above command will spawn a container from the specified image file, execute the command python --version, print the output and then exit the container.

Building a Singularity image

It is not possible to build an image (.sif file) from a Singularity definition file on Baskerville as this requires root privileges. Instead you should either copy the relevant .sif file from another location or utilise Sylabs’ Remote Builder service. (N.B. Singularity images must be x86_64 architecture type.)

Singularity’s cache and temporary directories

By default, Singularity uses the following directory to store its cache: ~/.singularity/cache. However, due to the limited size of users’ home directories on Baskerville we move the Singularity cache to the following location: /tmp/singularity/cache. This means that the Singularity cache does not persist between jobs. There could be situations where it is desirable to retain the cache between jobs, in which case please define the following environment variable as appropriate, whilst being mindful of available storage space:

export SINGULARITY_CACHEDIR=/path/to/preferred/cache/directory

Last update: September 29, 2021