<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.bwhpc.de/wiki/index.php?action=history&amp;feed=atom&amp;title=NEMO2%2FContainers%2FApptainer</id>
	<title>NEMO2/Containers/Apptainer - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.bwhpc.de/wiki/index.php?action=history&amp;feed=atom&amp;title=NEMO2%2FContainers%2FApptainer"/>
	<link rel="alternate" type="text/html" href="https://wiki.bwhpc.de/wiki/index.php?title=NEMO2/Containers/Apptainer&amp;action=history"/>
	<updated>2026-05-08T13:20:44Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.17</generator>
	<entry>
		<id>https://wiki.bwhpc.de/wiki/index.php?title=NEMO2/Containers/Apptainer&amp;diff=16051&amp;oldid=prev</id>
		<title>M Janczyk: Created page with &quot;&#039;&#039;&#039;Apptainer&#039;&#039;&#039; (formerly Singularity) is a container runtime designed for HPC systems. It is installed system-wide on NEMO and available without loading a module.  == Key properties ==  * Runs as the invoking user — no root required and no privilege escalation * Uses SIF (Singularity Image Format), a single portable file * Can convert Docker images to SIF at build time * No native Slurm plugin — call &lt;tt&gt;apptainer exec/run&lt;/tt&gt; inside your batch script  == Image sou...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.bwhpc.de/wiki/index.php?title=NEMO2/Containers/Apptainer&amp;diff=16051&amp;oldid=prev"/>
		<updated>2026-05-07T17:14:23Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;#039;&amp;#039;&amp;#039;Apptainer&amp;#039;&amp;#039;&amp;#039; (formerly Singularity) is a container runtime designed for HPC systems. It is installed system-wide on NEMO and available without loading a module.  == Key properties ==  * Runs as the invoking user — no root required and no privilege escalation * Uses SIF (Singularity Image Format), a single portable file * Can convert Docker images to SIF at build time * No native Slurm plugin — call &amp;lt;tt&amp;gt;apptainer exec/run&amp;lt;/tt&amp;gt; inside your batch script  == Image sou...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;Apptainer&amp;#039;&amp;#039;&amp;#039; (formerly Singularity) is a container runtime designed for HPC systems.&lt;br /&gt;
It is installed system-wide on NEMO and available without loading a module.&lt;br /&gt;
&lt;br /&gt;
== Key properties ==&lt;br /&gt;
&lt;br /&gt;
* Runs as the invoking user — no root required and no privilege escalation&lt;br /&gt;
* Uses SIF (Singularity Image Format), a single portable file&lt;br /&gt;
* Can convert Docker images to SIF at build time&lt;br /&gt;
* No native Slurm plugin — call &amp;lt;tt&amp;gt;apptainer exec/run&amp;lt;/tt&amp;gt; inside your batch script&lt;br /&gt;
&lt;br /&gt;
== Image sources ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Source !! Example&lt;br /&gt;
|-&lt;br /&gt;
| Apptainer Hub || &amp;lt;tt&amp;gt;apptainer pull hello-world.sif library://lolcow&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Docker Hub (converted) || &amp;lt;tt&amp;gt;apptainer pull ubuntu.sif docker://ubuntu:24.04&amp;lt;/tt&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Local &amp;lt;tt&amp;gt;.sif&amp;lt;/tt&amp;gt; file || copy to &amp;lt;tt&amp;gt;$HOME&amp;lt;/tt&amp;gt; or a workspace and use directly&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Image storage ==&lt;br /&gt;
&lt;br /&gt;
SIF files are plain files — store them wherever you like.&lt;br /&gt;
To avoid filling your home quota, keep images in a [[Workspaces|workspace]] and use a symlink so your scripts don&amp;#039;t need to change:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# create a workspace (100 days)&lt;br /&gt;
ws_allocate apptainer 100&lt;br /&gt;
&lt;br /&gt;
# create an images directory in the workspace and symlink it from home&lt;br /&gt;
ln -s $(ws_find apptainer) ~/images&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Pull images directly into the workspace:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apptainer pull ~/images/ubuntu.sif docker://ubuntu:24.04&lt;br /&gt;
apptainer pull ~/images/pytorch.sif docker://nvcr.io/nvidia/pytorch:24.01-py3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In batch scripts, reference images via the symlink:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
IMAGE=$HOME/images/pytorch.sif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Pull / build an image ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# from Docker Hub → produces ubuntu.sif in ~/images/&lt;br /&gt;
apptainer pull ~/images/ubuntu.sif docker://ubuntu:24.04&lt;br /&gt;
&lt;br /&gt;
# from NVIDIA NGC&lt;br /&gt;
apptainer pull ~/images/pytorch.sif docker://nvcr.io/nvidia/pytorch:24.01-py3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Run a command inside a container ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# exec: run a specific command&lt;br /&gt;
apptainer exec ubuntu.sif python3 script.py&lt;br /&gt;
&lt;br /&gt;
# run: execute the container&amp;#039;s default runscript&lt;br /&gt;
apptainer run ubuntu.sif&lt;br /&gt;
&lt;br /&gt;
# shell: interactive shell&lt;br /&gt;
apptainer shell ubuntu.sif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GPU access ===&lt;br /&gt;
&lt;br /&gt;
Pass the &amp;lt;tt&amp;gt;--nv&amp;lt;/tt&amp;gt; flag to enable NVIDIA GPU passthrough:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apptainer exec --nv pytorch.sif python3 train.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Bind-mount paths ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tt&amp;gt;/home&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;/work&amp;lt;/tt&amp;gt; are available inside the container by default (Apptainer automatically binds a set of paths; check &amp;lt;tt&amp;gt;apptainer config&amp;lt;/tt&amp;gt; for the system defaults).&lt;br /&gt;
&lt;br /&gt;
To mount additional directories explicitly:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apptainer exec --bind /work/classic/myWs:/data ubuntu.sif bash&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using Apptainer in a Slurm batch job ==&lt;br /&gt;
&lt;br /&gt;
Unlike Enroot/Pyxis there is no Slurm plugin; simply call &amp;lt;tt&amp;gt;apptainer&amp;lt;/tt&amp;gt; from your batch script:&lt;br /&gt;
&lt;br /&gt;
CPU job:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#SBATCH -p cpu&lt;br /&gt;
#SBATCH --ntasks=1&lt;br /&gt;
#SBATCH --time=01:00:00&lt;br /&gt;
&lt;br /&gt;
IMAGE=$HOME/images/ubuntu.sif&lt;br /&gt;
&lt;br /&gt;
apptainer exec &amp;quot;$IMAGE&amp;quot; python3 /work/classic/myWs/train.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
GPU job (use &amp;lt;tt&amp;gt;--nv&amp;lt;/tt&amp;gt; to pass through the allocated GPUs):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#SBATCH -p l40s&lt;br /&gt;
#SBATCH --gres=gpu:1&lt;br /&gt;
#SBATCH --ntasks=1&lt;br /&gt;
#SBATCH --time=01:00:00&lt;br /&gt;
&lt;br /&gt;
IMAGE=$HOME/images/pytorch.sif&lt;br /&gt;
&lt;br /&gt;
apptainer exec --nv &amp;quot;$IMAGE&amp;quot; python3 /work/classic/myWs/train.py&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Building images ==&lt;br /&gt;
&lt;br /&gt;
Building a new SIF image from a definition file requires root (or a system that supports fakeroot/user namespaces).&lt;br /&gt;
On NEMO you cannot build images directly on the compute nodes.&lt;br /&gt;
&lt;br /&gt;
Recommended workflow:&lt;br /&gt;
# Build on a machine where you have root (local workstation, VM, GitHub Actions, …)&lt;br /&gt;
# Transfer the &amp;lt;tt&amp;gt;.sif&amp;lt;/tt&amp;gt; file to NEMO (e.g. &amp;lt;tt&amp;gt;scp&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;rsync&amp;lt;/tt&amp;gt;)&lt;br /&gt;
# Run on NEMO as usual&lt;br /&gt;
&lt;br /&gt;
Store images in a workspace (symlinked to &amp;lt;tt&amp;gt;~/images/&amp;lt;/tt&amp;gt; as described above) — not in &amp;lt;tt&amp;gt;$TMPDIR&amp;lt;/tt&amp;gt;, which is job-local and deleted after the job.&lt;br /&gt;
&lt;br /&gt;
== Tips ==&lt;br /&gt;
&lt;br /&gt;
* Use &amp;lt;tt&amp;gt;apptainer exec --writable-tmpfs&amp;lt;/tt&amp;gt; if the container tries to write to its own filesystem (without persisting changes).&lt;br /&gt;
* The &amp;lt;tt&amp;gt;--containall&amp;lt;/tt&amp;gt; flag gives a fully isolated environment (no automatic bind-mounts); useful for reproducibility tests.&lt;br /&gt;
* To check what Apptainer version is installed: &amp;lt;tt&amp;gt;apptainer --version&amp;lt;/tt&amp;gt;&lt;/div&gt;</summary>
		<author><name>M Janczyk</name></author>
	</entry>
</feed>