All materials (c) 2020-2024 by CSC – IT Center for Science Ltd. This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 Unported License, http://creativecommons.org/licenses/by-sa/4.0/
sudo and namespaces unavailable in CSC systems due to safety reasonsroot:root inside the container but has no actual root privilegesbuild --remote option has been removed from Apptainer because there is no standard protocol or non-commercial service that supports itconda install commandslibrary: bootstrap agent does not work in Apptainer by default
bootstrap agent and source used to build the base OS
Example using “docker” bootstrap agent and an image from DockerHub:
Bootstrap: docker
From: ubuntu:20.04Example using “yum” bootsrtap agent and distrubution files from CentOs site:
Bootstrap: yum
OSVersion: 7
MirrorURL: http://mirror.centos.org/centos-%{OSVERSION}/%{OSVERSION}/os/$basearch/
Include: yum%setup, %files, %environment, %post, %runscript, %startscript, %test, %labels, %help%apps* sections for SCIF Apps supportin the host after the base container is runningCan be used to add files from the host system to the container
Syntax is: /path/in/host /path/in/container
%files
myfile /app/data/myfileCan be used to set any environment variables, e.g $PATH
%environment
export PATH=/app/bin:$PATHin the container after base container is running%post
apt install python3
pip install numpyDefines the runscript
%runscript
exec myprog "$@"' # Runs program "myprog" with command line options providedExecuted when container run with:
apptainer run myprog.sif
or
./myprog.sifSimilar to the %runscript section
Executed when run with:
apptainer start instance example.sifMainly used for containers that run services etc. Not that relevant on HPC environment
Runs at the very end of the build process to validate the container using a method of your choice
Can be run with:
apptainer test example.sifCan be used to add metadata, e.g. contact information
%labels
Maintainer my.address@example.netCan be seen with:
apptainer inspect --labels example.sifAdd usage instructions etc
%help
Usage:
apptainer exec myprog.sif myprog --helpCan be seen with:
apptainer run-help example.sifBootstrap: docker
From: ubuntu:20.04
%runscript
echo "This is what happens when you run the container..."
%files
hello_world /usr/bin/hello_world
hello2 /found/me/hello2
To build with a definition file:
sudo apptainer build myapp.sif myapp.def
or:
apptainer build --fakeroot myapp.sif myapp.defIf sudo or namespaces are not available --fakeroot is assumed so it can be omitted
--sandbox)
You can start with a simple definition file (just the header) or from a bootstrap agent:
apptainer build --fix-perms --sandbox myprog/ docker://ubuntu:22.04Depending on host file system you may need to specify --fix-perms
Creates a folder structure instead of an image file
You can copy files directly to correct subfolder
To open in writable mode use option --writable
apptainer shell --writable myprogDepending on base image system, package managers can be used to install libraries and dependencies (apt install , yum install etc)
--fakerootAlso --cleanenv may be needed
Installation as per software developer instructions
Build a production image from the sandbox
sudo apptainer build myprog.sif myprog
history can help, but if you try many things, keep track of what worked./home, /tmp, or any other directories that might get commonly binded on).%help or %apphelp section. A good container tells the user how to interact with it.%environment or %appenv sections of the build recipe.