Creating Containers
Containers allows you to package an application and its dependencies into a container image. This image contains everything needed to run the application, including libraries and environment variables.Containers are a convenient and efficient way to make your applications portable and reproducible.
Apptainer is the container platform available on Tempest. You do not need to load any modules to use Apptainer. The below documentation is pulled from Apptainer's documentation
For an overview of apptainer usage, run the following in the terminal:
apptainer --help
Pull an Image from Docker
As per your requirements, search the relevant docker image and use the following command to pull it.
(In this example we are using a python image from docker)
apptainer pull docker://python
This will pull the .sif file into your home directory on Tempest.
Run Your Code in the Container
The exec
command allows you to execute a custom command within a container by specifying the
image file.
Here I am using the python.sif (pulled in the previous step) and executing my custom python script in it.
apptainer exec python.sif python example.py
example.py is the name of my python file, present in the home directory on Tempest.
Since we are running python code in the container, there is no need to load the python module.
Run the Container in Slurm
In order to run the container in a slurm job, Here is an example:
#!/bin/bash #SBATCH --partition=test #SBATCH --cpus-per-task=2 #SBATCH --mem=2G #SBATCH --time=0-01:00:00 #SBATCH --job-name=container-example
# %x is the job name, and %j is the job number #SBATCH --output=%x-%j.out #SBATCH --error=%x-%j.err
echo "container test"
apptainer exec /home/<netID>/python.sif python /home/<netID>/pythonExample.py