Build containers¶
The standard SingularityCE way to build .sif
containers is from .def definition files.
Definition file¶
Rat-Containers contains several SingularityCE Definition Files available on GitLab at rat-containers/singularityCE.
These files follow a general structure:
example.def¶# Header section
# To boostrap from local image, first run:
# singularity pull <agent>://<provider>/<name>.sif
# and point to this image with the following header.
Bootstrap: localimage
From: ./<name>.sif
# Otherwise to use provider directly:
# Bootstrap: <agent>
# From: <provider>/<name>.sif
# Commands to run post creation of the OS in container
%post
# Common steps are:
# 1. Update package manager and packages
apt-get update
# 2. Install dependencies and setup environment
apt-get install -y xeyes
# 3. Build desired packages
make stuff-up
# 4. Clean-up
rm -rf cache
# Scripts to run for `singularity run <container> [<args>]`
# Will be used to print info and exit in Rat-Containers cases
%runscript
# Script to run, if needed
echo "Cycling..."
# Metadata: printed by `singularity inspect <container>`
%labels
# Key value pairs defining labels, parsed as:
<attribute> <value>
# e.g.
author vacuuous.rom@byrg.com
program.version 1.0.0
# Help: printed by `singularity run-help <container>`
# Raw text to print to the console
%help
SingularityCE Definition File structure example
Check out Rat-Containers on GitLab:
https://gitlab.com/project-rat-extras/rat-containers
Build command¶
These files can then be used to build containers like so:
sudo singularity build --force <container>.sif <definition_file>.def
Note
The --force flag overwrite labels and metadata
from previous images if bootstrapped from them.
Chaining images¶
Building containers from scratch can get quite cumbersome iterations after iterations. Moreover one might need to acquire a custom base image to bootstrap from for different containers.
One solution to this is “chaining images”:
Bootstrap from online base image of interest (e.g. Rocky Linux 8 with CUDA) to generate local image with complete desired environment.
Bootstrap from generated local image and so on and so forth.
Note
The rat-containers/singularityCE directory contains chained images for Project-Rat and for pyRat. One could of course “flatten” the recipes in order to have a full self contained definition file for their container instead of building each one of them incrementally.