Skip to content

Apptainer#

Apptainer is a platform that allows running containers in HPC environments. Originally, Singularity was the tool used for this purpose, but its development was forked into Apptainer, which is now the recommended standard in the HPC community.

Warning

Singularity is now deprecated and will be removed in the future, so we recommend users migrate their workflows to Apptainer.

Apptainer supports running containers with MPI and GPU support. Additionally, it can be integrated into Slurm scripts without issues.

Using Apptainer at TeideHPC#

Info

We currently have version 1.3.6 of Apptainer available at TeideHPC.

We can load the software using modules:

$ module load Apptainer/1.3.6
$ apptainer -h

Docker Containers#

Apptainer uses its own container format .sif, so Docker containers must be converted. However, this is done automatically without user intervention.

Downloading Containers from DockerHub#

Info

Container downloads should always be performed from the login nodes, which have Internet access, and not from the compute nodes.

Example of downloading an image from DockerHub for use in the cluster:

apptainer pull docker://hello-world

This will generate an image file in the current directory:

hello-world_latest.sif

To run the container:

Warning

Running software on login nodes is not allowed. Use salloc to request a compute node and execute it there.

apptainer run hello-world_latest.sif

If we need to build a container from Docker, we can use:

apptainer build mycontainer.sif docker://ubuntu:latest

Running a Container#

To run a container:

apptainer run mycontainer.sif <arg-1> <arg-2> ... <arg-N>

We can also execute a specific command inside the container:

apptainer exec mycontainer.sif <command> <arg-1> <arg-2> ... <arg-N>

To get an interactive shell inside the container:

apptainer shell mycontainer.sif

Running a Container in Slurm#

We can run Apptainer in Slurm like any other software:

#!/bin/bash -l

#SBATCH -J apptainer_job
#SBATCH -p batch
#SBATCH --nodes=1
#SBATCH -o out.log
#SBATCH -e err.log

module load Apptainer/1.3.6

apptainer run $HOME/hello-world_latest.sif

Slurm treats Apptainer like any other software, applying the same resource constraints, such as CPU, memory, and time limits.

Using MPI#

Tip

MPI support depends on the software being executed, not Apptainer. Therefore, we ask users to carefully read their software documentation before running anything.

If the software inside the container supports MPI, we can run it with srun:

#!/bin/bash -l

#SBATCH -J apptainer_mpi
#SBATCH -p batch
#SBATCH --nodes=2
#SBATCH -o out.log
#SBATCH -e err.log

module purge
module load Apptainer/1.3.6
module load GCC/12.2.0 OpenMPI/4.1.4

srun apptainer run $HOME/hello-world_latest.sif

Using GPU#

Tip

GPU support depends on the software being executed, not Apptainer. Therefore, we ask users to carefully read their software documentation before running anything.

To use a GPU, we need to add the --nv (enable Nvidia support) parameter to Apptainer:

apptainer run --nv mycontainer.sif

Example in Slurm:

#!/bin/bash -l

#SBATCH -J apptainer_gpu
#SBATCH -p gpu
#SBATCH --cpus-per-task=4
#SBATCH --gpus=a100:1
#SBATCH -o out.log
#SBATCH -e err.log

module purge
module load Apptainer/1.3.6

apptainer run --nv $HOME/hello-world_latest.sif

Other Options#

We can bind directories from the host inside the container using -B:

apptainer run -B /usr/lib/locale/:/usr/lib/locale -B "${PWD}/input":"/input" mycontainer.sif <command> <arg-1> ... <arg-N>