Using Containers in HPC with Apptainer (formerly Singularity)
Quick Start
After having successfully installed Apptainer on your system the initial step is to run your first container.
apptainer run docker://ghcr.io/apptainer/lolcow
Output
INFO: Converting OCI blobs to SIF format
INFO: Starting build...
INFO: Fetching OCI image...
45.8MiB / 45.8MiB [============================================================] 100 % 0.0 b/s 0s
27.2MiB / 27.2MiB [============================================================] 100 % 0.0 b/s 0s
INFO: Extracting OCI image...
INFO: Inserting Apptainer configuration...
INFO: Creating SIF file...
[============================================================] 100 % 0s
_______________________________
< Sat Sep 19 12:42:10 CEST 2026 >
-------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
The leading docker:// part instructs Apptainer to look for the image in
Docker Hub.
With a leading library:// in the image name Apptainer looks for the image in
the Singularity Cloud Library.
This is the equivalent to Docker Hub in the
Apptainer world.
Let's try another example by running an Ubuntu image using Apptainer. Therefore, let us use the
apptainer run docker://ubuntu:26.04
Output
INFO: Converting OCI blobs to SIF format
INFO: Starting build...
INFO: Fetching OCI image...
39.6MiB / 39.6MiB [=============================================================] 100 % 4.6 MiB/s 0s
INFO: Extracting OCI image...
INFO: Inserting Apptainer configuration...
INFO: Creating SIF file...
[==========================================================================================] 100 % 0s
Apptainer>
Using this command we are presented a shell inside the Ubuntu Apptainer container.
Usually, we are logged in as the same user as you are on the host system
inside a container.
Let's look at the python example again, run a container and execute a shell
to illustrate this:
apptainer run docker://python:latest sh
Output
INFO: Converting OCI blobs to SIF format
INFO: Starting build...
INFO: Fetching OCI image...
64.7MiB / 64.7MiB [=============================================================] 100 % 4.9 MiB/s 0s
225.4MiB / 225.4MiB [===========================================================] 100 % 4.9 MiB/s 0s
5.8MiB / 5.8MiB [===============================================================] 100 % 4.9 MiB/s 0s
28.4MiB / 28.4MiB [=============================================================] 100 % 4.9 MiB/s 0s
24.5MiB / 24.5MiB [=============================================================] 100 % 4.9 MiB/s 0s
47.1MiB / 47.1MiB [=============================================================] 100 % 4.9 MiB/s 0s
INFO: Extracting OCI image...
INFO: Inserting Apptainer configuration...
INFO: Creating SIF file...
[=========================================================================================] 100 % 0s
Apptainer>
Apptainer> whoami
mueller1234
Apptainer automatically makes the current directory available as the home
directory (/home/$USER) in the container.
Unlike with Podman, it is not necessary to explicitly mount the directories.
They are made available by default.
Apptainer> touch foo
Apptainer> exit
$ ls
foo
As you already saw in the examples above, with Apptainer, you can easily reuse existing
images from Docker Hub and run them as an Apptainer container.
Let us run a specific python:3.13 Docker Hub
image as an Apptainer container.
Therefore, we pull the image first.
apptainer pull docker://python:3.14
Output
INFO: Converting OCI blobs to SIF format
INFO: Starting build...
INFO: Fetching OCI image...
5.8MiB / 5.8MiB [===============================================================] 100 % 4.9 MiB/s 0s
28.4MiB / 28.4MiB [=============================================================] 100 % 4.9 MiB/s 0s
24.5MiB / 24.5MiB [=============================================================] 100 % 4.9 MiB/s 0s
47.1MiB / 47.1MiB [=============================================================] 100 % 4.9 MiB/s 0s
64.7MiB / 64.7MiB [=============================================================] 100 % 4.9 MiB/s 0s
225.4MiB / 225.4MiB [===========================================================] 100 % 4.9 MiB/s 0s
INFO: Extracting OCI image...
INFO: Inserting Apptainer configuration...
INFO: Creating SIF file...
[=========================================================================================] 100 % 0s
This command downloads the image from Docker Hub (docker://) and converts it
into the Apptainer specific image format called SIF file.
A file called python_3.14.sif was created in your current directory.
Run it as shown below.
apptainer run python_3.14.sif
Output
Python 3.14.7 (main, Sep 19 2026, 03:33:58) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Apptainer Definition Files
As demonstrated in the Podman build lesson we want to build our first custom
Apptainer image as well.
Therefore, we need to create the Apptainer definition file, i.e. the
equivalent to Dockerfile.
We will recreate the lolcow image used for the first run command in this episode.
Therefore, we create a file called lolcow.def using the editor of your choice.
This file contains the construction manual for the Apptainer image.
Bootstrap: docker
From: ubuntu:26.04
%post
apt-get -qy update
apt-get -qy install fortune cowsay lolcat
%environment
export LC_ALL=C
export PATH=/usr/games:$PATH
%runscript
fortune | cowsay | lolcat
Build the image using the apptainer build command.
apptainer build lolcow.sif lolcow.def
Output
INFO: Starting build...
INFO: Fetching OCI image...
39.6MiB / 39.6MiB [===============================================================] 100 % 0.0 b/s 0s
INFO: Extracting OCI image...
INFO: Inserting Apptainer configuration...
INFO: Running post scriptlet
+ apt-get -qy update
[...]
+ apt-get -qy install fortune cowsay lolcat
[...]
done.
INFO: Adding environment to container
INFO: Adding runscript
INFO: Creating SIF file...
[=========================================================================================] 100 % 0s
INFO: Build complete: lolcow.sif
This command creates the file lolcow.sif.
It is run using the apptainer run command.
apptainer run lolcow.sif
Output
_________________________________________
/ Of course you have a purpose -- to find \
\ a purpose. /
-----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Let's take apart the Apptainer definition file.
Header
Each Apptainer definition file needs to start with the header part consisting
of at least the Bootstrap keyword.
In our example we use the docker bootstrap agent telling Apptainer to
get the image from a Docker registry.
This agent needs to be combined with the From keyword to let Apptainer know,
which base image to use.
Bootstrap: docker
From: ubuntu:26.04
Usage of Other Registries
If you want to use another registry, e.g. the Helmholtz Codebase GitLab Container Registry, it is easily possible. Specify the full name of the image according to the GitLab Container Registry naming convention as described in the documentation.
Generic example:
Bootstrap: docker
From: <registry domain>/<namespace>/<project>/<image>
Helmholtz Codebase GitLab example:
Bootstrap: docker
From: hcr.helmholtz.cloud/hueser93/my-helloworld-image-project
apptainer remote login -u hueser93 docker://hcr.helmholtz.cloud
apptainer build hello.sif hello.def
apptainer run hello.sif
A list of preferred bootstrap agents is available here.
Sections
The main content of the definition file is broken into sections. In our example we used three different sections:
%post- In this section you can download files from the internet with tools like
git,wgetorpip, - You can install new software and libraries,
- Create configuration files,
- Create files and directories, etc.
- In this section you can download files from the internet with tools like
%environment- This section allows you to define environment variables which are set at runtime.
- These variables are not set at build time,
when running the
apptainer buildcommand.
%runscript- The commands specified in this section are executed when the container
image is run. (
apptainer run)
- The commands specified in this section are executed when the container
image is run. (
Please refer to the official documentation for a complete list of available sections and their usage.
Apptainer vs. Podman
| Podman | Apptainer | |
|---|---|---|
| Isolation from host | Shares little by default. | Isolation not the primary focus. By default shares most everything. |
| Supported Host Operating Systems (OS) | Windows, Mac, Linux | Linux |
| Data Persistence | No host filesystem available by default. | Writable bind-mounts of the user home directory are automatically created. |
| Primary target group | Developers, DevOps | Scientific Application Users/Developers |
| HPC | Not suitable for HPC: requires elevated permissions | Integrates well with MPI, GPUs, Infiniband and Schedulers (e.g. SLURM) |
| Ecosystem | Larger ecosystem; more sophisticated registries and preconfigured images | Smaller ecosystem; is able to use Docker images. |