Apptainer is a container platform, and is a popular alternative to Docker on HPC clusters. It allows you to run containers that package up pieces of software in a way that is portable and reproducible. You can build a container using Apptainer on your laptop, self-managed desktop or a virtual machine and then run it on a DICE desktop or server or even move it to the cloud or a HPC cluster.
Apptainer is fully compatible with Singularity. Apptainer is an actively maintained community-led Linux Foundation project. On DICE, we make Apptainer available on all Ubuntu Compute and Teaching Cluster nodes (landonia nodes).
There is an Apptainer user's guide that you should use to familiarise yourself with the software.
Using Apptainer on DICE
Apptainer isn't installed on all DICE computers by default, but it is on compute and cluster nodes. Check that it is installed by simply running this command in a terminal window:
apptainer --version
If this returns command not found
please raise a ticket requesting for its installation on your DICE machine.
The most common usage of Apptainer is to download pre-built images from an external resource like the Container Library, GitHub Container Registry. On GPU nodes, you can make use of images from the NVIDIA NGC catalogue.
The user manual has examples of using these docker and oci registries.
Singularity was configured to use Sylabs servers for libraries by default. If you want to use their behaviour, you will now need to follow the documentation's instructions to restore the Singularity behaviour .
You can use the pull
command to download pre-built images. The following example uses a docker image from the GitHub container registry, downloads it to the file lolcow_latest.sif
and runs it.
apptainer pull docker://ghcr.io/apptainer/lolcow apptainer exec ./lolcow_latest.sif cowsay DICE rocks
Apptainer and AFS
When pulling images from Container Library a single image file (.sif
) is downloaded. When pulling docker images, the single image file will be built on the fly. For this reason Apptainer uses temporary and cache folders. As the default location for these folders is inside your home folder (~/.apptainer
APPTAINER_TMPDIR and APPTAINER_CACHEDIR
. Please consider adding these to your .brc
or .bashrc
file. The below is just an example:
export APPTAINER_TMPDIR=/disk/scratch/$USER/singularity/temp export APPTAINER_CACHEDIR=/disk/scratch/$USER/singularity/cache
You may need to create those directories. So after setting the environment variables, create them like this:
mkdir -p $APPTAINER_TMPDIR $APPTAINER_CACHEDIR
Interacting with images
The shell
command allows you to spawn a new shell within your container and interact with it as though it were a small virtual machine.
apptainer pull docker://ghcr.io/apptainer/lolcow apptainer shell ./lolcow_latest.sif Singularity>
The change in prompt (to Singularity>
) indicates that you have entered the container. Once inside the container, you are the same user as you are on the DICE machine. You can leave the container by entering exit
or using the standard ctrl-d
key combination.
The exec
command allows you to execute a custom command within a container by specifying the image file. For instance, to execute the cowsay program within the lolcow_latest.sif
container:
apptainer exec lolcow_latest.sif cowsay moo _____ < moo > ----- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||
Singularity containers contain runscripts. These are user defined scripts that define the actions a container should perform when someone runs it. The runscript can be triggered with the run command, or simply by calling the container as though it were an executable. Both commands below will give the same result.
apptainer run lolcow_latest.sif
or
./lolcow_latest.sif
Working with files
By default Apptainer bind mounts your home folder, /tmp
and current working directory into the container at runtime. You can specify additional directories to bind mount into your container with the --bind
option. e.g:
apptainer shell lolcow_latest.sif Singularity> ls /disk/scratch ls: cannot access '/disk/scratch': No such file or directory Singularity> exit apptainer shell --bind /disk/scratch lolcow_latest.sif Singularity> ls /disk/scratch/ lost+found miniconda3
Working with GPUs
Apptainer does not bind GPU(s) to containers by default. Please use --nv
parameter to do so.
apptainer shell --nv lolcow_latest.sif Singularity> nvidia-smi -L GPU 0: NVIDIA GeForce RTX 2060 (UUID: GPU-c9a1b80d-f5ab-2e6c-27df-b742c57f487e)
As an example of what you can do, NVIDIA makes a pytorch image available in its catalogue.
apptainer pull docker://nvcr.io/nvidia/pytorch:24.12-py3 apptainer exec --nv ./pytorch_24.12-py3.sif python3 >>> import torch >>> print(torch.cuda.is_available()) True
Build images from scratch
To build containers requires a machine you have root privileges for. As this is not the scope of this quick start guide please refer to Apptainer user's guide.
For any issues or further help please get in touch.