HPC High Performance Computing: 10.2 Building containers from Singularity definition files

1) Create a directory to build the image

$ mkdir image
$ cd image

1.1) Write a file with the settings

The extension used to create the definition file is .def. In the following example, we will create an apache2 container:

$ vi apache.def

Bootstrap: docker
From: ubuntu:18.04
%post
    apt-get -y update
    apt-get -y install apache2
%runscript
    apache2

2) Build the image

The following steps are an example to create an own singularity image on a local computer/server (not on login or calculation nodes) and then transfer it to your HPC home.

$ singularity build apache.sif apache.def

3) Other options

One main point of singularity is that it allows downloading an existing container from Docker Hub or the Container Library.

3.1) Downloading an existing container from Docker Hub

You can download Docker images from Docker Hub with a compatible file format to run with singularity:

$ singularity build pytorch.sif docker://bitnami/pytorch

INFO:    Starting build...
Getting image source signatures
Copying blob a2b89359fa38 done  
Copying blob f07f02243890 done  
Copying blob d07cc545acce done  
Copying blob 3d67eb6a506a done  
Copying blob a6152e0e0760 done  
Copying blob 276f930b1055 done  
Copying blob 76e1f11b6e64 done  
Copying blob 43fb780b72c7 done  
Copying blob 177015dde01d done  
Copying blob 9ec8f48b4f93 done  
Copying config 6ede1309fd done  
Writing manifest to image destination
Storing signatures
2022/02/24 09:36:46  info unpack layer: sha256:a2b89359fa388e295765580f49f084c927c8bdccd0b780030ba84f2a7b8ac4a9
2022/02/24 09:36:47  info unpack layer: sha256:f07f02243890df33f3404b58a16603d5fac9fcbb8900751494d874dd725855c2
2022/02/24 09:36:47  info unpack layer: sha256:d07cc545accee88bb63f7489e4a15cb7d26fa48926d03cb6c694e7867c221c3b
2022/02/24 09:36:47  info unpack layer: sha256:3d67eb6a506a0a8e4fd54892069254a884f4010b49b58fddb8d5fdffe98ff6b9
2022/02/24 09:36:49  info unpack layer: sha256:a6152e0e07604beb30fea0b341bf02c991661567272a59d99b4a54406d1eeec0
2022/02/24 09:37:04  info unpack layer: sha256:276f930b105535a4c6275e911f24a32489eb3e1831d47c9a73bc1ad72a282e14
2022/02/24 09:37:04  info unpack layer: sha256:76e1f11b6e646ee1a9d1f75959957c232d8efed784e93b2a94c9fbf0b82e3378
2022/02/24 09:37:04  info unpack layer: sha256:43fb780b72c7969d9298123a5152b34efe1ddfeb4c397131fe6e40b050dc7efc
2022/02/24 09:37:04  info unpack layer: sha256:177015dde01dfc8e245ad4ad8b5c3361ccb1c1ab0d44f2410f918b60ac962ea8
2022/02/24 09:37:04  info unpack layer: sha256:9ec8f48b4f93fb5dcb1623658b9b614fb74d13eacc7199da2964292165a9c899
INFO:    Creating SIF file...
INFO:    Build complete: pytorch.sif

3.2) Downloading an existing container from the Container Library

You can use public container libraries or your own library from https://cloud.sylabs.io/library to download the image:

$ singularity build jupyter.simg library://sylabs-jms/testing/jupyter

INFO:    Starting build...
INFO:    Downloading library image
2.1GiB / 2.1GiB [===================================================================================================================================================================] 100 % 28.6 MiB/s 0s
INFO:    squashfs image was compressed with xz, if it failed to run, please contact image's author
INFO:    Verifying bootstrap image /root/.singularity/cache/library/sha256.6f32ea510217eb4b0d3186ae85860b2532973afd68f67207896c24f2dca4e05c
WARNING: integrity: signature not found for object group 1
WARNING: Bootstrap image could not be verified, but build will continue.
INFO:    Creating SIF file...
INFO:    Build complete: jupyter.simg