Singularity / Apptainer

Overview

Singularity (now maintained as Apptainer) is the container runtime of choice on shared HPC clusters. Unlike Docker it does not require root privileges, making it compatible with multi-user systems. You can pull any Docker image from BioContainers and convert it to a Singularity Image File (.sif) that runs under your normal user account.

Installation

On most HPC systems Apptainer is pre-installed as a module:

module load apptainer   # or: module load singularity

On a personal Linux machine, install from the official packages:

# Ubuntu / Debian
sudo apt install -y apptainer

# CentOS / RHEL / Fedora
sudo dnf install -y apptainer

Verify the installation:

singularity --version

Basic Usage

Converting a Docker image

singularity pull downloads a Docker image and converts it into a .sif file.

# On HPC: convert Docker image to Singularity/Apptainer
singularity pull docker://biocontainers/fastqc:v0.12.1

This creates fastqc_v0.12.1.sif in the current directory.

Running a tool

Use singularity exec to run a command inside the container:

singularity exec fastqc_v0.12.1.sif fastqc sample_R1.fastq.gz

By default Singularity bind-mounts your home directory and the current working directory, so input files are visible without extra flags.

Running inside a SLURM job

Containers work seamlessly with SLURM. Replace direct tool calls with singularity exec:

#!/bin/bash
#SBATCH --job-name=fastqc_singularity
#SBATCH --cpus-per-task=4
#SBATCH --mem=8G
#SBATCH --time=01:00:00

module load apptainer

singularity exec fastqc_v0.12.1.sif \
  fastqc -t 4 sample_R1.fastq.gz sample_R2.fastq.gz

Key Parameters

singularity exec

Flag

Description

--bind src:dst

Bind-mount a host path into the container (e.g. --bind /scratch:/scratch).

--pwd

Set the working directory inside the container.

--cleanenv

Start with a clean environment (ignore host environment variables).

--nv

Enable NVIDIA GPU support (for GPU-accelerated tools such as Dorado).

--contain

Isolate the container – do not auto-mount home or temp directories.

singularity pull

Flag

Description

--dir

Directory to store the .sif file.

--force

Overwrite an existing .sif file.

--disable-cache

Do not cache layers (useful on systems with small /tmp).

Expected Output

After pulling and running the FastQC container you will have:

fastqc_v0.12.1.sif         # Singularity image file (~250 MB)
sample_R1_fastqc.html      # FastQC report
sample_R1_fastqc.zip       # FastQC data archive

See Also