Working with containersο
Singularity tutorial 1ο
π¬ In this tutorial, we will get familiar with the basic usage of Singularity containers.
Getting startedο
Download a test container image:
wget https://a3s.fi/saren-2001659-pub/tutorial.sif ls -lh tutorial.sif
The file we downloaded is a container image. It contains all the software and data of the container in a single file. In this case, the container is very bare-bones and thus quite small, about 40 MB.
Actual application containers are typically larger since they also contain the software installation and may in some cases include reference data, etc.
Basic usageο
π¬ There are three basic ways to run software in a Singularity container:
singularity exec
ο
To execute a command inside the container, use
singularity exec
:singularity exec tutorial.sif hello_world
Compare the outputs of the following commands:
grep "^NAME" /etc/os-release singularity exec tutorial.sif grep "^NAME" /etc/os-release
The first command is run on the host, the second command is run inside the container.
π The tutorial container is based on Ubuntu 18.04. The host and the container use the same kernel, but the rest of the system can vary.
This means that a container can be based on a different Linux distribution than the host (as long as they are kernel-compatible), but it canβt run a totally different OS, such as Windows or macOS.
In batch jobsο
π‘ singularity exec
is the run method you would typically use in batch job
scripts.
Create a file called
test.sh
:nano test.sh
Copy the following contents into the file and replace
<project>
with your actual LUMI project, e.g.project_465001234
:#!/bin/bash #SBATCH --job-name=test # Name of the job visible in the queue. #SBATCH --account=<project> # Choose the billing project. Has to be defined! #SBATCH --partition=debug # Job queues: https://docs.lumi-supercomputer.eu/runjobs/scheduled-jobs/partitions/ #SBATCH --time=00:01:00 # Maximum duration of the job. Max: depends of the partition. #SBATCH --mem=1G # How much RAM is reserved for job per node. #SBATCH --ntasks=1 # Number of tasks. Max: depends on partition. #SBATCH --cpus-per-task=1 # How many processors work on one task. Max: Number of CPUs per node. singularity exec tutorial.sif hello_world
Submit the job to the queue with:
sbatch test.sh
π‘ For more information about batch jobs, see the batch jobs section.
singularity run
ο
π¬ When containers are created, a standard action called the runscript
is
defined. Depending on the container, it may simply print out a message, or it
may launch a program or service inside the container.
π If you are using a container created by someone else, you will need to check the documentation provided by the creator for details.
In our test container the
runscript
prints out a simple message:singularity run tutorial.sif
Give the container image execution rights so that you can run it directly:
chmod u+x tutorial.sif ./tutorial.sif
You can see the actual script with the command:
singularity inspect --runscript tutorial.sif
singularity shell
ο
Open a shell inside the container:
singularity shell tutorial.sif
Notice that the command prompt changed. You can now run any software inside the container interactively:
hello_world
Exit the container with:
exit
More informationο
π¬ This tutorial is meant as a brief introduction to get you started.
π‘ For more detailed instructions, see the official Singularity documentation.