Path: blob/master/part-2/containers/apptainer-tutorial-part1.md
696 views
---
---
Apptainer tutorial
💬 In this tutorial, we will get familiar with the basic usage of Apptainer (previously Singularity) containers.
To run these exercises on Puhti, use
sinteractive
or open a compute node shell in the Puhti web interface.
Getting started
Download a test container image from Allas:
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 50 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 an Apptainer container:
Apptainer exec
To execute a command inside the container, use
apptainer exec
:Compare the outputs of the following commands:
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
💡 apptainer exec
is the run method you would typically use in batch job scripts.
Create a file called
test.sh
:Copy the following contents into the file and replace
<project>
with your actual CSC project, e.g.project_2001234
:Submit the job to the queue with:
💡 For more information about batch jobs, see the batch jobs section.
Apptainer 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:Give the container image execution rights so that you can run it directly:
You can see the actual script with the command:
Apptainer shell
Open a shell inside the container:
Notice that the command prompt changed. You can now run any software inside the container interactively:
Exit the container with:
More information
💬 This tutorial is meant as a brief introduction to get you started.
☝🏻 When searching online for instructions, pay attention that the instructions are for the same version of Apptainer as you are using. There has been some command syntax changes etc. between versions, so older instructions may not work as is. Also note that Apptainer was formerly known as Singularity.
💡 For more detailed instructions, see the official Apptainer documentation.