This lesson is being piloted (Beta version)

Introduction to Apptainer/Singularity

Key Points

Introduction
  • Apptainer/Singularity is a container platform designed by and for scientists.

  • Single-file based container images facilitates the distribution.

  • Secure. User inside the container = user outside.

Containers and Images
  • Use singularity --version to know what you are using and to communicate it if asking for support

  • A container can be started from a local .sif or directly with the URL of the image.

  • Apptainer is also compatible with Docker images, providing access to the large collection of images hosted by Docker Hub.

  • Get a shell inside of your container with apptainer shell <path/URL to image>

  • Execute a command inside of your container with apptainer exec <path/URL> <command>

  • Bind outside directories with --bind

Coffee break!
Building Containers
  • The command build is the basic tool for the creation of containers.

  • A sandbox is a writable directory where containers can be built interactively.

  • Superuser permissions are required to build containers if you need to install packages or manipulate the operating system.

  • Use interactive builds only for development and tests, use definition files for production or publicly distributed containers.

Containers from definition files
  • An Apptainer definition file provides an easy way to build and deploy containers.

Coffee break!
Sharing files between host and container
  • Bind mounts allow reading and writing files within the container.

  • In Apptainer, you have same owner and permissions for files inside and outside the container.

  • Some paths are mounted by default by Apptainer.

  • Additional directories to bind can be defined using the --bind option or the environment variable $SINGULARITY_BIND.

Apptainer/Singularity instances
  • Instances allow to setup services via Apptainer images or definition files.

  • Code provided in Jupyter notebooks can be accompanied by a Apptainer/Singularity image with the environment needed for its execution, ensuring the reproducibility of the results.

Bonus Episode: Building and deploying an Apptainer container to GitHub Packages
  • Python packages can be installed in apptainer images along with ubuntu packages.

  • It is possible to publish and share apptainer images over github packages.