UA Research Computing

HPC Examples

Intro to Containers


Contents

shipping

Creating a Container

Running Apptainer on HPC

Running Apptainer on HPC as a Batch Job

Binding File Paths

GPUs and Containers

References






Apptainer

note that if you create many containers many gigibytes of cache files may be written to ~/.apptainer. The files can be safely deleted, so be careful not to fill your home directory.

First start an interactive session

[laptop ~]$ ssh netid@hpc.arizona.edu
[netid@gatekeeper ~]$ shell
(puma) [netid@wentletrap ~]$ elgato
(elgato) [netid@wentletrap ~]$ interactive
[netid@cpu37 ~]$ apptainer help
[netid@cpu37 ~]$ apptainer help build

Creating a Container

Pull from Docker registry

Less reproducible – image can change

apptainer pull docker://godlovedc/lolcow

Pull from container library

More reproducible

apptainer pull library://sylabsed/examples/lolcow

Build from Docker registry

More optionsconverts to latest format, & needs a name

apptainer build lolcow.sif docker://godlovedc/lolcow

Running Apptainer on HPC

Apptainer shell

apptainer shell opens a command prompt to the environment inside the container. Try executing some commands. Notice that although you are inside the container (a separate operating system), you will be able to list the contents of your home directory.

[netid@i16n2 ~]$ apptainer shell lolcow_latest.sif
Apptainer> 
Apptainer> exit

Apptainer run

apptainer run executes the default run script within the container, which was specified when the container was created.

[netid@i16n2 ~]$ apptainer run lolcow_latest.sif
[netid@i16n2 ~]$ # Or
[netid@i16n2 ~]$ ./lolcow_latest.sif
[netid@i16n2 ~]$ apptainer run library://sylabsed/examples/lolcow
INFO:    Using cached image
 _______________________________________
/ Wrinkles should merely indicate where \
| smiles have been.                     |
|                                       |
\ -- Mark Twain                         /
 ---------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Apptainer on HPC as a Batch Job

No modules need to be loaded to execute a container in a Slurm batch submission.

#!/bin/bash
#SBATCH --job-name=lolcow
#SBATCH --ntasks=1 
#SBATCH --nodes=1 
#SBATCH --mem=1gb 
#SBATCH --time=00:01:00 
#SBATCH --partition=standard 
#SBATCH --account=YOUR_GROUP 


cd /path/to/container
apptainer run lolcow_latest.sif

Binding File Paths

Access to your files outside the container: Binding You automatically get /home, /tmp, /xdisk, /groups, and $PWD

[netid@i16n8 ~]$ echo "Hello from inside the container" > $HOME/hostfile.txt
[netid@i16n8 ~]$ apptainer exec lolcow_latest.sif cat $HOME/hostfile.txt
Hello from inside the container
[netid@i16n8 ~]$ echo "Drink milk (and never eat hamburgers)." > data/cow_advice.txt
[netid@i16n8 ~]$ apptainer exec --bind $PWD/data:/mnt lolcow_latest.sif cat /mnt/cow_advice.txt
Drink milk (and never eat hamburgers).

Alternatives:

$ apptainer shell --bind /data my-container.sif
$ export APPTAINER_BINDPATH=/data

GPUs and Containers

We show three ways to use tensorflow containers on HPC. We just use Tensorflow as an example

  1. Tensorflow example using a system module*
  2. Tensorflow using a custom image pulled from Nvidia
  3. Tensorflow from DockerHub

    *Containers as modules: caffe, pytorch, rapids, tensorflow, and theano

References

Reference Link
UA HPC Containers Documentation https://public.confluence.arizona.edu/display/UAHPC/Containers
UA HPC Examples Github https://ua-researchcomputing-hpc.github.io
NIH Containers Documentation https://hpc.nih.gov/apps/Apptainer.html
Sylabs User Guide https://sylabs.io/guides/3.5/user-guide/introduction.html
Sylabs Examples https://github.com/sylabs/examples
TACC Container Basics https://containers-at-tacc.readthedocs.io/en/latest/
CyVerse Container Camp https://cyverse-container-camp-workshop-2018.readthedocs-hosted.com
Tensorflow User Guide https://www.tensorflow.org/tutorials/quickstart/beginner