Singularity is a container technology especially suitable for high-performance computing (HPC) environments. It can deploy and run analysis pipelines without requiring root privileges at runtime, while providing good portability, security, and a relatively low learning cost.

Basic concepts and features

Singularity depends on Go, so Go should be installed before installing Singularity. It is also recommended to prepare root privileges for the installation process.

You can refer to the official Go documentation for Go installation instructions.

First, create and enter an empty directory to store the downloaded installation files. Then install Singularity with the following commands:

1. Ubuntu:

Bash
# Install additional tools and dependencies
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev uuid-dev libgpgme11-dev squashfs-tools libseccomp-dev wget pkg-config git cryptsetup debootstrap
            
# Install Go
wget https://dl.google.com/go/go1.13.linux-amd64.tar.gz
sudo tar --directory=/usr/local -xzvf go1.13.linux-amd64.tar.gz
export PATH=/usr/local/go/bin:$PATH
            
# Download Singularity source code
wget https://github.com/singularityware/singularity/releases/download/v3.5.3/singularity-3.5.3.tar.gz
tar -xzvf singularity-3.5.3.tar.gz
            
# Install Singularity
cd singularity
./mconfig
cd builddir
make
sudo make install

2. CentOS (the commands have not been fully tested; try them step by step):

Bash
# Install dependencies
yum install -y gcc libuuid-devel squashfs-tools openssl-devel make

# Install Go
export VERSION=1.17.2 OS=linux ARCH=amd64   
wget https://dl.google.com/go/go$VERSION.$OS-$ARCH.tar.gz 
tar -C /usr/local -xzvf go$VERSION.$OS-$ARCH.tar.gz
rm -f go$VERSION.$OS-$ARCH.tar.gz 
echo 'export PATH=/usr/local/go/bin:$PATH' >> /etc/profile
source /etc/profile

# Install Singularity
export VERSION=3.9.2
wget https://github.com/sylabs/singularity/releases/download/v${VERSION}/singularity-ce-${VERSION}.tar.gz 
tar -xzf singularity-ce-${VERSION}.tar.gz
cd singularity-ce-${VERSION}
./mconfig --prefix=/opt/singularity/${VERSION}
cd builddir/
make && make install
echo "export PATH=/opt/singularity/${VERSION}/bin:\$PATH" >> /etc/profile

The most basic way to use Singularity is to create a container that contains the software and dependencies you need. It is recommended to perform container construction with root privileges.

1. Base container:

Bash
# Download a base system container
singularity pull library://library/default/ubuntu

2. Generate a sandbox container:

Bash
# Create a sandbox container
singularity build --sandbox <software_name>/ ubuntu_latest.sif

3. Enter the sandbox and install the required software:

Bash
# Enter the sandbox
singularity shell --writable <software_name>/

# Using the shell parameter enters a shell environment based on the sandbox container,
# Next, install the required software and dependencies as on a regular Linux system.
# After installation, run exit to leave the sandbox.

4. Package the sandbox into a static SIF file:

Bash
# Package the sandbox into a static SIF file
singularity build <software_name>.sif <software_name>/

5. Run software from the static SIF file:

Bash
# Run software with Singularity
singularity exec <software_name>.sif <software_cmd>