Show Menu
Cheatography

Apptainer Cheat Sheet by

A quick reference guide for using Apptainer

Pulling images

apptainer pull <ou­tpu­t.s­if> shub:/­/[r­epo­sio­ry/­name/]
Pull sif image from Singul­arity Hub
apptainer pull <ou­tpu­t.s­if> docker­://­[do­cke­r_i­mage]
Pull Docker image from Dockerhub or remote container registry
apptainer pull <ou­tpu­t.s­if> docker­-da­emo­n:/­/[i­mag­e_name]
Pull docker image from local Docker image builds
Before a Docker image can be used by Apptainer, it must be pulled to make it compatible with Apptainer.

Apptainer Cache

apptainer cache list
Show basic details on what is in the local cache
apptainer cache list -v
Lists SIF images stored in the local cache
apptainer cache clean
Remove everything stored in the local cache
By default, Apptainer stores the cache in
$HOME/.ap­pta­ine­r/cache
, but can be changed by modifying the
APPTAI­NER­_CA­CHEDIR
variable

Executing commands from a image

apptainer exec [SIF_F­ile.sif] <co­mma­nd_­to_­exe­cut­e>
Execute a command from the image
apptainer run [SIF_F­ile.sif]
Executes the default command for the image
apptainer inspect -r [SIF_F­ile.sif]
Inspect the SIF image and locate the default command
apptainer shell [SIF_F­ile.sif]
Open an intera­ctive shell within the container

Binding host direct­ories to a container

apptainer shell -B /direc­tor­y/t­o/add [SIF_F­­il­e.sif]
Add a directory to the same location in the container
apptainer shell -B /direc­tor­y/t­o/a­dd:­/ne­w/l­oca­tio­n/i­n_c­ont­ainer [SIF_F­­il­e.sif]
Add a directory to a different location in the container
The "­-B" arguement can apply to the
shell
,
exec
, and
run
sub commands of Apptainer.
shell
is only used as an example. This is refered to as "Binding­" the directory inside of the container.

Building Apptainer Images

apptainer build /path/­to/­oup­ut.sif /path/­to/­inp­ut.def
Build a sif image using the .def definition file.

Apptainer Definition File Keywords

Apptainer
Docker Equivalent
Descri­ption
From:
FROM
Base image for the image
%files
ADD
Add files from the host system into the image
%envir­onment
ENV
Add enviro­nment variables to the image
%post
RUN
Run commands to build or install software in the image
%runscript
CMD / ENTRYPOINT
What to run when the container is used with
apptainer run
%setup
 
Run commands on the host system before starting the build
%labels
LABEL
Add metadata labels
Bootstrap
 
Tells Apptainer which type of source the base image will be.
   
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          ROCKS Cluster Commands Cheat Sheet