Modules with Containers
Modules can also be setup in such a way they will utilize apptainer containers. This can be useful for codes which prerequisits are difficult to meet if not sudo user.
An example is given here for the application ffmpeg but it can be easily modified to run with whatever other container from any library. This code is used to produce high quality video from simulation files obtained with ParaView. The ufficial guide to compile on centos is given here. It can be noticed right away how complex such compilation would be to simply be able to run the ffmpeg executable as many prerequisites are needed (nasm, yasm, etc...).
By using a docker container ffmpeg-docker this task can be easily done. However, setting un a module for everybody to use involving containers necessitates a few extra steps.
ffmpeg
Example Usage#
The ffmpeg module can be laoded using the following command:
As soon as it is loaded the following message gets displayed:
What this means is that the container will be downloaded into the user apptainer cache folder which usually resides in /mmfs1/home/myName/.apptainer
.
This folder can be changed by exporting the proper environment variable:
and as a reminder, the last message will say how big is the cache folder (remember there is a 10gb limit on user home directories) and where the cache folder is currently located. In the above example, the folder size is 306mb and it resides in /mmfs1/home/adeleo/.apptainer/
. The cache folder can be cleaned by running the command apptainer cache clean
.
caution
The only available commands to use with the containers are noted in the message! In this example, only the commands ffmpeg
and ffprobe
can be used!
By running the ffmpeg
command, if the container is not in cache, apptainer will download the docker and then it will run the command followed the arguments needed.
This is great because now every user can load these modules and use commands that run directly out of containers!
#
Module Creation and SetupIn this section a more in-details example of how create modules that utilize containers will be given.
The .lua module file (located in /sw/contrib/modulefiles/mamslab/ffmpeg/4.4.lua
) of the containerized ffmpeg package is the following:
By following the above example, other modules can be easily created. It is important to properly document links, changes, and which commands can be execute by the container.
The last for loop creates shell functions which can be run in your compute node.
In this example, if you look up the function ffmpeg
this is what you will get:
What this means is that instead of using an executable called ffmpeg, you will actually call a function which runs:
apptainer exec
: is calling apptainer and requesting to perform an "action" via theexec
command.--home \folder
: is setting up the working directory as the home directory in the container.--bind \folder
: it binds the folder to the container.\gscratch
is recommended.docker://address
: is the address of the container."%@"
: the arguments following the function call.
tip
The command --home $PWD
means that wherever you are running the function from, it will match as working directory in the container. This is because whenever the container is run, it automatically goes to the home folder.
#
Run the container as shell (advanced)With a bit of familiarity of containers, after loading the module is also possible to run the container as an interactive shell.
This is done by copying the shell function and replacing exec
with shell
and removing the explicit ffmpeg
function and the shell bash arguments "%@"
. Doing so leads to the following:
Now the container can be run as if it were a proper interactive session!