
Singularity/Apptainer on the SCC
The main command for using singularity/apptainer is /usr/bin/apptainer and can be called directly with either apptainer or singularity. Please refer to the Singularity/Apptainer documentation at https://apptainer.org/documentation/ for general use information.
Singularity vs Apptainer
Singularity recently underwent a name change to Apptainer. It is the same project as Singularity and Apptainer maintains backwards compatibility with Singularity.
The changes include:
- the command line interface changed from
singularity–>apptainer. - you now define environmental variables for your container by prepending
APPTAINERENV_instead ofSINGULARITYENV_. If you use the oldSINGULARITYENV_syntax, you will be presented with a warning. - User configurations are now stored in
~/.apptainerinstead of in~/.singularity.
Please refer to this webpage for more extensive documentation on the singularity –> apptainer change: https://apptainer.org/docs/user/latest/singularity_compatibility.html
Wrapper for Singularity/Apptainer
In order to facilitate integration with the SCC, we provide a command wrapper scc-singularity:
[rcs@scc1 ~] scc-singularity run my_container.sif
The wrapper is available on the PATH for general use and provides the following features:
- Automatically binds:
- user’s home directory
- user’s project spaces
- the node(s)
/scratch /usr/local/share
- Preserves and passes into the container SCC environment variables:
DISPLAYNSLOTSTMPDIRUSER
- Will detect if using GPU(s) and pass
CUDA_VISIBLE_DEVICESinto the container.
If the container has code installed into its own /usr/local directory, then pass the --nolocal flag to scc-singularity:
[rcs@scc1 ~] scc-singularity --nolocal run my_container.sif
The --scc-preview and --scc-debug commands can be used to print out the command executed by the scc-singularity wrapper:
[rcs@scc1 ~] scc-singularity --scc-preview run my_container.sif
/usr/bin/singularity run -e -B /share -B /usr1 -B /usr2 -B /usr3 -B /usr4 -B /var/spool/sge -B /project -B /projectnb -B /projectnb2 -B /scratch -B /net -B /ad -B /usr/local -B /var/lib/dbus/machine-id my_container.sif
preview mode - command not executed
Interactive Usage
Singularity can be used to run a shell interactively inside a container. This is accomplished using the shell subcommand. To try these commands, first get a copy of a container running the Debian 11 operating system from the Sylabs container library. This will create a container file called debian_11.sif:
[rcs@scc1 ~] apptainer pull library://debian:11
Now try to run the container:
[rcs@scc1 ~] apptainer shell debian_11.sif
Apptainer> grep PRETTY_NAME /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
It is important to note that standard “shell” mode will not provide full environment settings required to interact with modules and other SCC provided features.
The scc-singularity command has an additional subcommand myshell which invokes your default login shell with your complete login environment.
[rcs@scc1 ~] scc-singularity myshell debian_11.sif
Batch Usage
There are two main subcommands for running Singularity in batch: exec and run.
- Use the
execsubcommand to execute the specified command within the container.#!/bin/bash -l #$ -P proj_name #$ -N singularity_exec #$ -j y # Run the container and execute a command within it. scc-singularity exec debian_11.sif grep PRETTY_NAME /etc/os-release
- Use the
runsubcommand to run the command that the container is pre-configured to run.#!/bin/bash -l #$ -P proj_name #$ -N singularity_run #$ -j y # Run the container and run its preconfigured command. scc-singularity run debian_11.sif
