Recap of The Basics of Containers¶
Before we move on, let's quickly remind ourselves of what we covered in The Basics of Containers.
What is a container?¶
A container packages a piece of software together with all of its dependencies into a single, portable file. That file runs the same way on your own computer and on an HPC like Mahuika, which makes your work reproducible and easy to share. In Apptainer, a built container is a single sif file (Singularity Image Format).
The commands you should know¶
These are the commands we will lean on here:
| Command | What it does |
|---|---|
run |
Runs the container as its creator intended (the %runscript). |
exec |
Runs a custom command of your choice inside the container. |
shell |
Opens an interactive session inside the container. |
pull |
Downloads a container from the cloud as a sif file. |
build |
Builds a sif container from a def file, or a sandbox with --sandbox. |
For example, to run a container, execute a one-off command in it, or open a shell:
apptainer run my_container.sif
apptainer exec my_container.sif echo "Hello World!"
apptainer shell my_container.sif
Building a container from a def file¶
A def file is the recipe for a container. The key sections are:
BootstrapandFrom— the base image your container is built on (required).%labels— metadata such as the author and version.%environment— environment variables that are set when the container runs.%post— the commands that install and configure everything inside the container.%runscript— what happens when someone runs the container withapptainer run(arguments come in as$1,$2, … and$@).
A simple example:
You then build it into a sif file with:
Sandboxes and encrypted containers¶
We also saw two other ways of working with containers:
- Sandbox mode — build a container interactively with
apptainer build --sandbox, change it withapptainer shell --writable --contain --fakeroot, and turn the finished sandbox into asifcontainer withapptainer build. - Encryption — protect the contents of a container with either a passphrase (
--passphrase) or an RSA key pair (--pem-path), so it stays encrypted at rest, in transit, and while running.
What's coming up¶
Beyond the Basics builds on these foundations to:
- inspect, "edit", and version containers,
- add tests to containers, and
- run containers in parallel across an HPC using MPI.
Quick check
Before we start, make sure you can answer these:
- What is the difference between
run,exec, andshell? - What does the
%postsection of adeffile do? - How would you build a
sifcontainer from adeffile? - When would you use a sandbox instead of a
deffile?
If any of these are fuzzy, the earlier chapters are a good place to refresh.