Image Registry
This section illustrates the use of a container registry with two common examples from the user community. A registry is a repository for storing container images. A container image encapsulates an application. In the simplest case, users can download pre-build containers from the developer of the software they want to use.
The most commonly used container registry is Docker Hub 1. Unfortunately frequent downloading container images from the GSI HPC infrastructure by users may reach rate limits applied by Docker Inc. with an error message similar to the following:
FATAL: While making image from oci registry:... toomanyrequests: You have reached your pull rate limit.
The entirety of the HPC network is seen as a single source of requests to the Docker infrastructure, hence rate limiting 2 can prevent anonymous access. Regular users of the Docker registry can overcome this limitation using a Docker account 3. Note that Apptainer support authentication with Docker 4 when pulling container images.
Python
Use the official images from the Python developer community 5 with the pull
sub-command to download a pre-build container from Docker Hub with the latest Python version. The exec
sub-command executes a custom command within a container:
# download the latest version of a Python container from Docker Hub
apptainer pull $APPTAINER_CONTAINERS/python.sif docker://python:latest
# check the version of Python by launching the container:
apptainer exec $APPTAINER_CONTAINERS/python.sif python --version
Typically users will execute a Python-script passing it as argument to Apptainer, following a simple hello-world:
# a simple hello world Python script
cat > $LUSTRE_HOM/hello_world.py <<EOF
#!/usr/bin/env python
print("hello world")
EOF
chmod +x $LUSTRE_HOME/hello_world.py
# run the script in the container environment
apptainer exec $APPTAINER_CONTAINERS/python.sif /tmp/hello_world.py
The run
sub-command executes the Python container with the default application. In this case the interactive Python interpreter is started for an interactive session (type exit
to leave the container):
» apptainer run $APPTAINER_CONTAINERS/python.sif
Python 3.7.4 (default, Jul 13 2019, 14:04:11)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
ROOT
Another example is to compile your own binary executable using a pre-build container from a registry. In order to illustrate this we will employ the container of the ROOT Data Analysis Framework 6 widely use in the HEP community. An official ROOT container 7 is available on Docker Hub and includes a recent version of the GNU C++ Compiler:
# download the latest ROOT container from Docker Hub
apptainer pull $APPTAINER_CONTAINERS/root.sif docker://rootproject/root
# show the version information for the GNU C++ compiler
apptainer exec $APPTAINER_CONTAINERS/root.sif g++ --version | head -n1
g++ (GCC) 9.1.1 20190503 (Red Hat 9.1.1-1)
The container includes the GNU C++ compiler, which we use with the following simple hello world program:
cat > $LUSTRE_HOME/src/hello.cpp <<EOF
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
}
EOF
# compile the hello world program
apptainer exec $APPTAINER_CONTAINERS/root.sif \
$LUSTRE_HOME/src/hello.cpp -o $LUSTRE_HOME/bin/hello
g++
# execute the compiled binary with the container environment
apptainer exec $APPTAINER_CONTAINERS/root.sif \
$LUSTRE_HOME/bin/hello
Footnotes
Container Image Search, Docker Hub
https://hub.docker.com/search↩︎Understanding Docker Hub Rate Limiting
https://www.docker.com/increase-rate-limits/↩︎Docker Account Signup
https://hub.docker.com/signup↩︎Apptainer User Manual - Docker CLI Authentication
http://apptainer.org/docs/user/main/docker_and_oci.html#docker-cli-authentication↩︎Official Python Container Images, Docker Hub
https://hub.docker.com/_/python↩︎ROOT Data Analysis Framework
https://root.cern.ch↩︎Official ROOT Container Images, Docker Hub
https://hub.docker.com/u/rootproject↩︎