Examples
This section contains examples of building and running containers on Puhti and Mahti.
Example: Python virtual environment
Next, we provide an example of a container with system Python and virtual environment with Python packages installed using Pip. We can define the build definition as follows:
Bootstrap: docker
From: docker.io/rockylinux/rockylinux:8.10
%post
# Replace the failing commands with always succeeding dummies.
cp /usr/bin/true /usr/sbin/useradd
cp /usr/bin/true /usr/sbin/groupadd
# Install Python with system package manager.
dnf -y update
dnf -y install python3.11 python3.11-pip
dnf -y clean all
# Create a Python virtual environment and install packages using pip.
python3.11 -m venv /opt/venv
export PATH=/opt/venv/bin:$PATH
python3.11 -m pip install --no-cache-dir numpy
%environment
export PATH=/opt/venv/bin:$PATH
Now, we can build the container image as follows:
Finally, we can execute commands inside the container. For example, we can test the container by listing the Pip installed Python packages:
Example: Extending a local image
We can also extend existing SIF images.
In this example, we extend the python-pip.sif
container image by adding another Python library to it as follows:
Bootstrap: localimage
From: python-pip.sif
%post
python3.11 -m pip install --no-cache-dir pandas
Now, we build the container as normal:
Let's list the Pip installed packages to see the packages that we added:
Example: Using Make to build containers
Makefiles are a great way to organize the logic for building containers. If you are not familiar with how Makefiles work, we recommend reading the excellent Makefile Tutorial.
Here is an example of using a Makefile to build a container from a definition file named container.def
into a SIF file named container.sif
.
TMPDIR ?= /tmp
PREFIX := .
CONTAINER_SIF := $(PREFIX)/container.sif
CONTAINER_DEF := container.def
.PHONY: all
all: $(CONTAINER_SIF)
$(CONTAINER_SIF): $(CONTAINER_DEF)
apptainer build --fakeroot --bind=$(TMPDIR):/tmp $@ $<
.PHONY: clean
clean:
rm -f $(CONTAINER_SIF)
Let's invoke Make to build the container:
We can also invoke make with arguments such as PREFIX
to build the container into a different directory:
Example: Accelerated visualization application
Start by building the visualization base image which contains VirtualGL, its dependencies, and utility scripts.
We can build the accelerated visualization applications such as Blender on top of the visualization base image.
Application should be executed with the vglrun_wrapper
script installed in the base container.
Other application containers
CSC has container build recipes for various applications in the singularity-recipes repository. Here are the recipes that can be built with Apptainer using fakeroot on Puhti and Mahti: