Apptainer (formerly Singularity)

Apptainer (formerly Singularity)

Apptainer is a software container solution that enables users to have full control of their environment.

Description

Apptainer is a free, cross-platform and open-source computer program that performs operating-system-level semi-virtualization also known as containerization. One of the main uses of Apptainer is to bring reproducible environments to scientific computing and the high-performance computing (HPC) world.

A container once built can be used on different systems providing the exact same software environment everywhere.

Using Apptainer containers, developers can design and test their specific environments on their own alongside with their application, and these complete environments can easily be copied and executed on other platforms eg. Supercomputers.

Prerequisites

No group membership or license is needed. Apptainer can be used by all NHR@ZIB users by default.

Modules

Selecting the version and loading the environment

Load the modulefile

module load apptainer

This provides access to the binary apptainer which can be used to manage and run containers.

Running containers

Apptainer can run containers from it’s own .sif file format or use Docker/Podman/OCI images which are then converted.

Running containers from .sif file

apptainer run -f debian.sif

Using existing Docker containers

apptainer run docker://debian:latest

For more information see the official docs about what formats Apptainer can handle.

Building images

If you want to package your software into a personal container to have to prepare it first on your personal computer since building images for Apptainer requires root privileges.

Once done, you can copy the container image (.sif file) into your NHR@ZIB account.

Build containers with a definition file

Create a definition file that looks like this:

# my_hpc_special_software.def BootStrap: docker From: debian:13 %post apt-get -y update apt-get -y install libcrumble gcc vim %files /home/user/source/my_hpc_special_software /opt/foo/bin/ %environment export FI_PROVIDER=tcp export PATH=/opt/foo/bin:$PATH %runscript /opt/foo/bin/my_hpc_special_software -D %labels Author Alice

Afterwards you can create a .sif image file from that definition:

# create .sif file from the exported image apptainer build my_hpc_special_software.sif my_hpc_special_software.def # test the image apptainer run -f my_hpc_special_software.sif # copy the image to NHR@ZIB scp my_hpc_special_software.sif user@blogin.nhr.zib.de:

 

Convert local Docker/Podman images

# export from docker docker save -o my_hpc_special_software.tar my_hpc_special_software:1.0-rc3 # create .sif file from the exported image apptainer build my_hpc_special_software.sif docker-archive://my_hpc_special_software.tar # test the image apptainer run -f my_hpc_special_software.sif # copy the image to NHR@ZIB scp my_hpc_special_software.sif user@blogin.nhr.zib.de:

The same workflow works also with podman.

Example Jobscripts

Here is an example job of running the local Singularity image (.sif)

#!/bin/bash #SBATCH -p medium #SBATCH -N 1 #SBATCH -t 60:00 module load apptainer apptainer exec /home/user/my_hpc_special_software.sif /opt/foo/my_hpc_special_software --test -b30

Binding directories

Sometimes it is required to have some specific paths in container, which are not mounted by default. For instance /scratch is not available per default inside the container so to get access to your project file or $TMP_DIR you must explicitly mount it.

apptainer exec --bind /scratch /home/user/my_hpc_special_software.sif ls -l /scratch/projects/....

 

Cluster Specifics

A100

There is also a Apptainer example available for the GPU A100 partition.