Developer Guide

Build a Singularity* Container for an MPI Application

There are several ways to build Singularity* containers described in the Singularity official documentation.
This section demonstrates how to build a container for an MPI application from scratch using recipes. Singularity recipes are files that include software requirements, environment variables, metadata, and other useful details for designing a custom container.

Recipe File Structure

A recipe file consists of the header and sections. The header part defines the core operating system and core packages to be installed. In particular:
  • Bootstrap
    - specifies the bootstrap module.
  • OSVersion
    - specifies the OS version. Required if only you have specified the %{OSVERSION} variable in
  • MirrorURL
    - specifies the URL to use as a mirror to download the OS.
  • Include
    - specifies additional packages to be installed into the core OS (optional).
The content of a recipe file is divided into sections that execute commands at different times during the build process. The build process stops if a command fails. The main sections of a recipe are:
  • %help
    - provides help information.
  • %setup
    - executes commands on the host system outside of the container after the base OS is installed.
  • %post
    - executes commands within the container after the base OS has been installed at build time.
  • %environment
    - adds environment variables sourced at runtime. If you need environment variables sourced during build time, define them in the %post section.

Build a Container

After the recipe file is created, use it to create a Singularity container. The example below shows how to build a container with default parameters:
$ singularity build mpi.img ./Singularity_recipe_mpi

Product and Performance Information


Performance varies by use, configuration and other factors. Learn more at