Apptainer (Singularity) Basics

What is Apptainer?

Apptainer (formerly Singularity) is a container platform created specifically for High-Performance Computing (HPC) and research.

It solves the problem of “Dependency Hell” by packaging your code, data, and the specific operating system it needs into a single, portable file.

Why it matters for research

Absolute Reproducibility

If your code runs in an Apptainer container today, it should still run the same way years from now. The container freezes the operating system and library versions, protecting your science from future system updates.

True Portability

Apptainer compresses your entire environment into a single file (.sif). You can copy this file from your laptop to the cluster, email it to a collaborator, or archive it with your data. “It works on my machine” means it works on any Linux machine with the same processor type (e.g. x86-64). On a Mac or Windows laptop it needs a Linux virtual machine, and GPU or MPI jobs also depend on the host’s drivers.

HPC & Cluster Safe

Unlike Docker, Apptainer runs containers as your own user. You do not need administrator (root) privileges to run it. This makes it the standard, secure choice for shared university clusters.

Compatible with Docker

You don’t have to build everything from scratch. Apptainer can run standard Docker images directly. You can pull almost any tool from Docker Hub and run it instantly on the cluster.

Core concepts

The Image (.sif)

The final product. A Singularity Image Format (SIF) file is a read-only, compressed file that acts like a portable hard drive containing your software environment.

Definition File

The “recipe” used to build an image. It is a text file where you specify the base OS (e.g., Ubuntu 20.04) and the list of commands to install your software.

Bind Mounts

The bridge between the container and the outside world. Apptainer automatically “binds” (mounts) your home directory and the current directory — and on many clusters also scratch — so you can read/write your data files effortlessly without moving them inside the container. Use --bind for other paths.

The Shell

You can “enter” a container interactively (apptainer shell). Your terminal prompt changes, and you are effectively working inside a different operating system, but you can still see your personal files.

The Builder

The process of converting a Recipe or a Docker image into a SIF file. Note: You often need root access (or the --fakeroot flag) to build an image, but never to run it.

Overlay

Since SIF images are read-only (immutable), an “overlay” is a writable layer (temporary, or saved in its own file) you can place on top if you need to install something quickly without rebuilding the whole image.

Common Misconceptions & FAQ

Why can’t I just use Docker? 🐳

Reality: Docker requires “root” (sudo) access to run daemon processes. Giving researchers root access on a shared cluster node is a massive security risk. Apptainer was designed to run without root, making it safe for HPC.

Can I edit files inside the container?

Reality: Generally, no. The container image (SIF) is read-only by design. This guarantees reproducibility. If you need to change software, you modify the Definition File and rebuild the image. (You can, however, edit your data files that live outside the container).

Does using a container slow down my code?

Reality: Negligible. Apptainer uses containerization (sharing the host kernel), not virtualization (emulating hardware). The performance overhead is usually near zero compared to running natively.