Apptainer
Apptainer (formerly known as Singularity) is a containerization tool designed for High-Performance Computing (HPC). Unlike Docker, it allows running containers without requiring root privileges, making it ideal for secure environments like supercomputers and university clusters.
Official Resources
- Website: Apptainer.org
- GitHub Repository: Apptainer GitHub
- Documentation: Official Docs
- Community: Apptainer Slack
Video Tutorials
- Apptainer: Deep Dive, Use Cases, and Examples
- A New Approach to MPI in Apptainer
- Benchmarking MPI Workloads in Apptainer
- GPU Computing in Apptainer
- Singularity/Apptainer in HPC Workshop
Basic Usage
If you have issues with using/creating an Apptainer image, unload the XALT module from your environment. To clear the entire environment, run: ml -f purge. To unload only the XALT module, use: ml -f -XALT.
Running a Container
apptainer run docker://ubuntuThis will pull an Ubuntu image from DockerHub and run it.
Shell Access
apptainer shell docker://ubuntuOpens an interactive shell inside the container.
Execute a Command
apptainer exec docker://ubuntu echo "Hello from Apptainer!"Building and Editing Images
Creating an Apptainer Definition File
Example my_container.def file:
Bootstrap: docker
From: ubuntu:20.04
%post
apt update && apt install -y python3
%runscript
echo "This is my custom Apptainer container!"Building an Image
apptainer build my_container.sif my_container.defEditing an Image
Apptainer images (.sif format) are immutable, so you need to create a writable sandbox:
apptainer build --sandbox my_container/ my_container.defModify it:
apptainer shell --writable my_container/Rebuild it into a .sif file:
apptainer build my_container_final.sif my_container/Using MPI in Apptainer
Running MPI Inside a Container
Your definition file should install MPI:
Bootstrap: docker
From: ubuntu:20.04
%post
apt update && apt install -y mpichBuild and run with MPI:
mpirun -np 4 apptainer exec my_mpi_container.sif mpi_hello_worldRunning MPI From Host Into Container
Ensure your host has an MPI runtime and mount it into the container:
mpirun -np 4 apptainer exec --bind /usr/lib/x86_64-linux-gnu/openmpi/ my_mpi_container.sif mpi_hello_worldGPU Support
Installing CUDA Inside a Container
For CUDA support, install the necessary drivers inside the image:
Bootstrap: docker
From: nvidia/cuda:12.0-runtime-ubuntu20.04Run with GPU:
apptainer exec --nv my_cuda_container.sif nvidia-smiTips and Tricks
-
Use
--fakerootto build withoutsudo:apptainer build --fakeroot my_container.sif my_container.def -
Use
--bind /host/path:/container/pathto access host directories. -
Convert Docker images to Apptainer format for offline use:
apptainer pull ubuntu.sif docker://ubuntu -
Debug with increased verbosity:
SINGULARITY_DEBUG=1 apptainer run my_container.sif
Conclusion
Apptainer is a powerful tool for running containers in HPC environments. With proper setup, it can efficiently run MPI workloads, GPU-accelerated applications, and custom software stacks while maintaining security and performance.

