Skip to content

Singularity

Singularity is an optional tool on our cluster that lets you run software inside portable containers without needing root access.

Each container runs under your own account, sees your usual home and scratch directories, and works smoothly with the scheduler.

Use it when you need software versions that aren’t already provided as modules.

Note

In our cluster Singularity is always accessible without need to load it using Lmod.

Note

Inside a job that requests scratch, SINGULARITY_CACHEDIR and SINGULARITY_TMPDIR point to the job's scratch directory, which is deleted when the job finishes. Download and build images on the login node and store the .sif files in your home or project directory, so they do not have to be downloaded again in every job.

Running Image

This example downloads and runs an image from the public library.

singularity run library://lolcow

Searching In Public Library

This example searches the public library for existing images.

singularity search tensorflow

Building Image

First create a Singularity definition file my_container.def using a text editor such as nano or vim.

Example content of my_container.def file:

Bootstrap: docker
From: ubuntu:24.04

%post
    apt-get update && apt-get install -y python3 python3-numpy

%runscript
    echo "This container has Python and NumPy installed!"
    python3

Now you can build the container:

singularity build my_container.sif my_container.def

After a successful build, you can run the container:

singularity run my_container.sif

Example output:

This container has Python and NumPy installed!
Python 3.12.3 ... on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Example

This PBS job script submits a job to the cluster to run a Python script (my_script.py) inside a Singularity container (my_container.sif).

#!/bin/bash
#PBS -N singularity_test
#PBS -l select=1:ncpus=4:mem=8gb
#PBS -l walltime=01:00:00

# Run your Singularity container
singularity exec my_container.sif python3 my_script.py