Skip to content

Singularity/Apptainer

Work in progress. Inspired by this.

1. No modules needed!

Singularity is installed directly into the images. This means it doesn't need to be loaded as a module any more. Also Singularity has been renamed to Apptainer. The command singularity is still available as a symlink to apptainer.

2. Set the cache folder to /scratch

When pulling containers, Singularity/Apptainer will create a $HOME/.apptainer/cache by default to store cache files, which can quickly use a lot of storage space. We recommend changing this location to a directory with more storage space (e.g., one of your scratch directories) by setting the environment variable APPTAINER_CACHEDIR. For example:

export APPTAINER_CACHEDIR=/scratch/$USER/.apptainer/cache

Add this line to your ~/.bashrc to automatically set this variable every time you log in. Use the command apptainer cache clean to clear the cache.

3. Pull a pre-built image

For example:

apptainer pull docker://rocker/r-base:3.6.3

Note: you can search for pre-built images with the following command:

apptainer search <image-name>

4. Running an apptainer image interactively

[<NetID>@login02 ~]$ apptainer shell r-base_3.6.3.sif
Apptainer> r --version
r ('littler') version 0.3.9

using GNU R Version 3.6.1 (2019-07-05)

Copyright (C) 2006 - 2019  Jeffrey Horner and Dirk Eddelbuettel

r is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License.  For more information about
these matters, see http://www.gnu.org/copyleft/gpl.html.

5. Running an apptainer image non-interactively

To non-interactively execute commands within a container, enter:

apptainer exec <container_image> <commands to execute>

For example:

apptainer exec mycontainer.sif python < python-input.py > python-output.log