In this system, it is possible to set up a container-based program execution environment using Singularity. This section describes how to prepare the container image, customize the container, and build it.
Preparing the container image
-
This section explains how to obtain a container image. Container images can be obtained from the local registry in SQUID (from the HPDA frontend only) or from a public registry on the Internet. You can also create your own container images and upload them to SQUID.
When using the work area, be sure to execute the newgrp command before executing.
1 2 3 |
$ groups ocean G12345 # Displays the groups to which you belong. "ocean" and "hpci" are administrative groups. $ newgrp G12345 |
download from the local registry
-
Download the singularity container image from the local registry and create a sandbox. This operation is available only in the HPDA frontend. As an example, to retrieve the container image named test registered in the local registry/master_image, navigate to the directory where you want to create the sandbox and execute the following command.
1 2 3 |
$ singularity build -f --sandbox --fix-perms <sandbox name> oras://cntm:5000/<Countainer image path>:<tag name> #The following is a sample of how to get the image "test". $ singularity build -f --sandbox --fix-perms test oras://cntm:5000/master_image/test:1.0 |
If the container image is successfully downloaded, a sandbox (test in the above example) will be created in the current directory.
download from Singularity Library
-
Download the singularity container image from the singularity library and create a sandbox.
For example, to get the centos container image from the singularity library, navigate to the directory where you want to create the sandbox, and execute the following command.
1 2 3 |
$ singularity build -f --sandbox --fix-perms <sandbox name> library://<Countainer image path>:<tag name> #The following is a sample of how to get a CentOS image . $ singularity build -f --sandbox --fix-perms centos library://emmeff/centos/centos:8 |
If the container image is successfully downloaded, a sandbox (centos in the above example) will be created in the current directory.
download from Docker Hub
-
Download the docker container image from Docker Hub and create a singularity sandbox.
For example, to get a centos container image from Docker Hub, navigate to the directory where you want to create the sandbox, and execute the following command.
1 2 3 |
$ singularity build -f --sandbox --fix-perms <sandbox name> docker://docker.io/<Countainer image path>:<tag name> #The following is a sample of how to get a CentOS image . $ singularity build -f --sandbox --fix-perms centos docker://docker.io/library/centos:latest |
If the container image is successfully downloaded, a sandbox (centos in the above example) will be created in the current directory.
Customizing and Building Container Images
-
This section describes how to customize and build container images. there are two ways to build container images with SQUID: directly customize and build the sandbox, or write the customization in a def file and customize it at build time.
Direct customization of the sandbox
-
This section explains how to customize and build the sandbox directly. First, acquire the base container image you want to customize, and create a sandbox beforehand. Next, launch the sandbox as a container. As an example, to customize a sandbox called test, execute the following command.
1 2 3 |
$ singularity run -f -w test The format is as follows $ singularity run -f -w <sandbox名> |
The next step is to build the container image and generate the sif file. As an example, to build a sandbox called test and create test.sif, execute the following command
1 2 3 |
$ singularity build -f test.sif test The format of the command is as follows $ singularity build -f <sif file> <sandbox name> |
How to describe the customization in the def file
This section explains how to write customization contents in a def file and customize it at build time. First, create a def file to be used for building.
As an example, if we want to customize the test registered in the local registry as the base container image, the def file will look like the following
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Bootstrap: oras From: cntm:5000/master_image/test:1.0 %files ./test.conf /opt/test.conf ./test_start.sh /opt/test_start.sh %post dnf install -y net-tools chmod 755 /opt/test_start.sh %runscript /opt/test_start.sh |
Def file summary *Please refer to the singularity manual for details. | |
---|---|
Bootstrap, From | Describe the type and location of the base image. |
%file | Describe the file you want to copy from the host OS to the container. |
%post | Describe the command for customization. |
%runscript | Describe the process to be executed automatically when the container starts. |
After the def file creation is complete, build the container image and generate the sif file. As an example, to build using a def file named test.def and create test.sif, execute the following command
1 2 3 |
$ singularity build -f test.sif test.def The format of the command is as follows $ singularity build -f <sif file> <def file> |