Apptainer documentation:

https://apptainer.org/

https://apptainer.org/docs/user/latest/

 

Apptainer Basics

Apptainer packages all of the code required to run the application inside a single image file (<filename>.sif). The application can be run by executing the container, the file systems inside the container are layered over the top of the OS system, so executables inside the container are executed, but directories outside the container can be written to if the user has permissions to write to them. 

An example of running a container:

  1. Download a container

    [ddholstad@a-lnx002:/var/tmp]$ apptainer pull docker://ghcr.io/apptainer/lolcow
    INFO:    Detected Singularity user configuration directory
    INFO:    Detected Singularity remote configuration, migrating...
    INFO:    Detected public Singularity pgp keyring, migrating...
    INFO:    Detected private Singularity pgp keyring, migrating...
    INFO:    Converting OCI blobs to SIF format
    INFO:    Starting build...
    Copying blob 16ec32c2132b done   | 
    Copying blob 5ca731fc36c2 done   | 
    Copying config fd0daa4d89 done   | 
    Writing manifest to image destination
    2024/09/30 14:22:19  info unpack layer: sha256:16ec32c2132b43494832a05f2b02f7a822479f8250c173d0ab27b3de78b2f058
    2024/09/30 14:22:20  info unpack layer: sha256:5ca731fc36c28789c5ddc3216563e8bfca2ab3ea10347e07554ebba1c953242e
    INFO:    Creating SIF file...

    [ddholstad@a-lnx002:/var/tmp]$ ls -l  lolcow_latest.sif
    -rwx------ 1 ddholstad clas-liberal-arts-administration-d1900   74969088 Sep 30 14:22 lolcow_latest.sif

  2. run the container (specifically, run the cowsay application from the lolcow_latest apptainer image)

    [ddholstad@a-lnx002:/var/tmp]$ apptainer exec lolcow_latest.sif cowsay moo
    _____
    < moo >
    -----
           \   ^__^
            \  (oo)\_______
               (__)\       )\/\
                   ||----w |
                   ||     ||
     
  3. Using an apptainer build file (lolcow.def in this case)

    Create a file named lolcow.def:

    BootStrap: docker
    From: ubuntu:22.04
    
    %post
       apt-get -y update
       apt-get -y install cowsay lolcat
    
    %environment
       export LC_ALL=C
       export PATH=/usr/games:$PATH
    
    %runscript
       date | cowsay | lolcat
    
    %labels
       Author Alice
  4. Use the lolcow.def to create a container file (lolcow.sif)
  5. apptainer build lolcow.sif lolcow.def
  6. Other considerations:

    1. When running on NFS home directories you may need to remap the TMP and Cache directories to locations that have space and that you have permissions to write to:

       SINGULARITY_TMPDIR=/scratch/tmp  apptainer build lolcow.sif lolcow.def
    2. Cachedir may also need to be remapped:

      SINGULARITY_CACHEDIR=/scratch/cache apptainer build  fos.img minimal.def

    The above directories are examples, please use a system appropriate directory when you actually run this (i.e. copy and paste wont work here).