π¬ In this tutorial, we will get familiar with the basic usage of Apptainer (previously Singularity) containers.
sinteractive
or open a compute node shell in the Puhti web interface.sinteractive --account <project> # replace <project> with your CSC project, e.g. project_2001234
wget https://a3s.fi/saren-2001659-pub/tutorial.sif
ls -lh tutorial.sif
π¬ There are three basic ways to run software in an Apptainer container:
exec
apptainer exec
:apptainer exec tutorial.sif hello_world
grep "^NAME" /etc/os-release
apptainer exec tutorial.sif grep "^NAME" /etc/os-release
π The tutorial container is based on Ubuntu 18.04. The host and the container use the same kernel, but the rest of the system can vary.
exec
in batch jobsπ‘ apptainer exec
is the run method you will typically use in batch job scripts.
test.sh
:module load nano # The compute nodes do not have nano available by default
nano test.sh
<project>
with your actual CSC project, e.g. project_2001234
:#!/bin/bash
#SBATCH --job-name=test # Name of the job visible in the queue.
#SBATCH --account=<project> # Choose the billing project. Has to be defined!
#SBATCH --partition=test # Job queues: test, interactive, small, large, longrun, hugemem, hugemem_longrun
#SBATCH --time=00:01:00 # Maximum duration of the job. Max: depends of the partition.
#SBATCH --mem=1G # How much RAM is reserved for job per node.
#SBATCH --ntasks=1 # Number of tasks. Max: depends on partition.
#SBATCH --cpus-per-task=1 # How many processors work on one task. Max: Number of CPUs per node.
apptainer exec tutorial.sif hello_world
sbatch test.sh
π‘ For more information on batch jobs, see Docs CSC.
run
π¬ When containers are created, a standard action called the runscript
is defined. Depending on the container, it may simply print out a message, or it may launch a program or service inside the container.
π If you are using a container created by someone else, you will need to check the documentation provided by the creator for details.
runscript
prints out a simple message:apptainer run tutorial.sif
chmod u+x tutorial.sif
./tutorial.sif
apptainer inspect --runscript tutorial.sif
shell
apptainer shell tutorial.sif
hello_world
exit
π¬ This tutorial is meant as a brief introduction to get you started.
βπ» When searching online for instructions, pay attention that the instructions are for the same version of Apptainer as you are using. There has been some command syntax changes etc. between versions so older instructions may not work as copy/paste. Also note that Apptainer is formerly known as Singularity.
π‘ For more detailed instructions, see the Apptainer documentation.