Skip to content

Containerisation with Apptainer

Apptainer docs

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

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

Apptainer replaces Singularity

The Apptainer application replaces the previous containerisation solution, Singularity. It is broadly a drop-in replacement and for now the command singularity will continue to function, although it will actually run Apptainer. For further information on the move from Singularity to Apptainer please see this article:

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 apptainer pull commands inside Slurm jobs and therefore on the compute nodes. (We recommend using an Interactive Job to do this.)

To pull an image from Docker Hub:

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

Two common methods for using an Apptainer container are exec and shell:

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

An example of apptainer exec:

apptainer 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 an Apptainer image

It is not possible to build an image (.sif file) from an Apptainer definition file on Baskerville as this requires root privileges. Instead you should copy the relevant .sif file from another location.

Apptainer’s cache and temporary directories

By default, Apptainer uses the following directory to store its cache: ~/.apptainer/cache. However, due to the limited size of users’ home directories on Baskerville we move the Apptainer cache to the following location: /tmp/apptainer/cache. This means that the Apptainer 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 APPTAINER_CACHEDIR=/path/to/preferred/cache/directory

Last update: October 19, 2022