💬 Apptainer containers have their own internal file system that is separated from the host file system.
💭 In most real use cases you might want to access the host file system to read and write files.
💡 This is done using the command line argument
-B). The basic syntax is
💭 Some remarks:
➖ The bind path does not need to exist inside the container – it is created if necessary.
➖ More than one bind pair can be specified.
➖ The option is available for all run methods described in the previous tutorial.
sinteractiveor open a compute node shell in the Puhti web interface:
sinteractive --account <project> # replace <project> with your CSC project, e.g. project_2001234
export SCRATCH=/scratch/<project>/$USER # replace <project> with your CSC project, e.g. project_2001234 apptainer exec tutorial.sif ls $SCRATCH
No such file or directoryerror.
/scratchto the directory
/scratchinside the container:
apptainer exec --bind $SCRATCH:/scratch tutorial.sif ls /scratch # or apptainer exec --bind /scratch:/scratch tutorial.sif ls $SCRATCH
💡 You can use
--bind to set the container, for example, to find input data or configuration files from a certain directory.
$SCRATCHto a directory called
apptainer exec --bind $SCRATCH:/input tutorial.sif ls /input
apptainer_wrapper, it will automatically take care of the most common bind use cases.
$SING_IMAGEenvironment variable to point to the correct Apptainer image file:
export SING_IMAGE=$PWD/tutorial.sif apptainer_wrapper exec ls $SCRATCH
💡 Note that the image file name is not needed in the
apptainer_wrapper command since
$SING_IMAGE is set.
‼️ Since some modules set
$SING_IMAGE when loaded, it is a good idea to start with
module purge to make sure the correct image is used if you plan to use
💬 Some software may require environment variables to be set, e.g., to point to some reference data or a configuration file.
💬 Most environment variables set on the host are inherited by the container.
☝🏻 Sometimes this may be undesired, in which case the command line option
--cleanenv can be used to prevent the host environment from being inherited by the container.
💬 To set an environment variable specifically inside the container, you can set an environment variable
XXX is the variable name) on the host before invoking the container.
export TEST1="value1" export APPTAINERENV_TEST2="value2"
env | grep TEST apptainer exec tutorial.sif env | grep TEST apptainer exec --cleanenv tutorial.sif env | grep TEST
$TEST1(inherited from the host) and
$TEST2(specifically set inside the container by setting
$APPTAINERENV_TEST2on the host).
apptainer exec tutorial.sif echo $TEST1 apptainer exec tutorial.sif echo $TEST2
$TEST2has not been set on host. It was
💬 Our test container includes the program
hello2, but it has not been added to the
findinside the container:
apptainer exec tutorial.sif find / -type f -name "hello2" 2>/dev/null
apptainer exec tutorial.sif /found/me/hello2
$PATHinside the container:
export APPTAINERENV_PREPEND_PATH=/found/me apptainer exec tutorial.sif hello2
💡 If you can’t locate the desired binary with
find, you can always use
apptainer shell to explore the container.
💬 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 copy/paste. Also note that Apptainer is formerly known as Singularity.
💡 For more detailed instructions, see the Apptainer documentation.