Running a Rocky8 apptainer image on Rocky9
If you absolutely need to still use the Rocky 8 software stack after the OS upgrade to Rocky 9, you can use it with Apptainer (formerly singularity).
We have an apptainer image with Rocky 8 and the same environment as the compute nodes. In addition, you can access the Rocky 8 modules from within the container. The image is stored at /cluster/software/containers/rocky8.sif
.
You can execute this image and/or copy it, but you cannot modify it in its original location.
NOTE: It works with the majority of software modules, but some may fail due to OS dependencies which are not longer compatible between the OS and the container.
Run apptainer with Rocky 8
To get a bash shell on a Rocky 8 environment, you can run:
[fox ~]$ apptainer run --nv /cluster/software/containers/rocky8.sif
Apptainer>
or
[fox ~]$ apptainer exec --nv /cluster/software/containers/rocky8.sif /bin/bash
Apptainer>
NOTE: The command apptainer shell
is also an option. However it does not allow you to access modules.
Load modules
You can still load modules that were available on Rocky 8 from inside the Apptainer container:
[fox ~]$ apptainer run --nv /cluster/software/containers/rocky8.sif
Apptainer> module avail
Apptainer> module load GCC/11.3.0
Apptainer> module list
Currently Loaded Modules:
1) GCCcore/11.3.0 2) zlib/1.2.12-GCCcore-11.3.0 3) binutils/2.38-GCCcore-11.3.0 4) GCC/11.3.0
Note that the modules are from the Rocky 8 environment:
Apptainer> module display matlab/R2022b-fasrc01
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/cluster/software/rhel8/easybuild/modules/all/GCC/11.3.0.lua:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
help([[
Description
===========
The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Java, and Ada,
as well as libraries for these languages (libstdc++, libgcj,...).
More information
================
- Homepage: https://gcc.gnu.org/
]])
whatis("Description: The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Java, and Ada,
as well as libraries for these languages (libstdc++, libgcj,...).")
whatis("Homepage: https://gcc.gnu.org/")
whatis("URL: https://gcc.gnu.org/")
conflict("GCC")
setenv("EBROOTGCC","/cluster/software/rhel8/easybuild/software/GCCcore/11.3.0")
setenv("EBVERSIONGCC","11.3.0")
setenv("EBDEVELGCC","/cluster/software/rhel8/easybuild/software/GCC/11.3.0/easybuild/GCC-11.3.0-easybuild-devel")
Submit slurm jobs
If you need to submit a job rather than getting to a shell, you have to do the following steps in the appropriate order:
- launch the apptainer image
- load modules
- (optional) compile code
- execute code
If you try to load modules before launching the image, it will try to load modules from the Rocky 9 host system.
To ensure that steps 2-4 are run within the apptainer container, they are place between END
(see slurm batch script below).
NOTE: You cannot submit slurm jobs from inside the container, but you can submit a slurm job that will execute the container.
Example with a simple hello_world.f90
fortran code:
program hello
print *, 'Hello, World!'
end program hello
Slurm batch script run_apptainer_rocky8.sh
:
#!/bin/bash
#SBATCH --account=MyProject
#SBATCH --job-name=rocky8
#SBATCH --time=00:10:00
#SBATCH --mem-per-cpu=2G
#SBATCH --ntasks=1
# start a bash shell inside apptainer image
apptainer run --nv /cluster/software/containers/rocky8.sif <<END
# load modules
module load GCC/11.3.0
module list
# compile code
gfortran hello_world.f90 -o hello.exe
# execute code
./hello.exe
END
To ensure that the commands are run within the apptainer container, they are placed between END
.
To submit the slurm batch script:
sbatch run_apptainer_rocky8.sh
Another option have a bash script with steps 2-4 and then use apptainer run
to execute the script. For example, script_inside_container.sh
:
#!/bin/bash
# load modules
module load GCC/11.3.0
module list
# compile code
gfortran hello_world.f90 -o hello.exe
# execute code
./hello.exe
And the slurm batch script run_apptainer_rocky8.sh
becomes:
#!/bin/bash
#SBATCH --account=MyProject
#SBATCH --job-name=rocky8
#SBATCH --time=00:10:00
#SBATCH --mem-per-cpu=2G
#SBATCH --ntasks=1
# start a bash shell inside apptainer image
apptainer run --nv /cluster/software/containers/rocky8.sif script_inside_container.sh
You can submit a batch job with:
sbatch run_apptainer_rocky8.sh
CC Attribution: This page is maintained by the University of Oslo IT FFU-BT group. It has either been modified from, or is a derivative of, "Running Singularity image with CentOS 7 on Rocky 8" by FASRC under CC-BY-NC-SA-4.0.