Contact Advanced Research Computing
Containers
Using containers in Linux has become a common practice in many business environments. Using technologies like Docker or Kubernetes, it is possible to create self-contained environments or “containers” that are designed for a specific purpose. Unfortunately, the use of these technologies in HPC has been problematic due to security concerns. The open source project Singularity addresses this problem, allowing for the creation of containers that maintain the security infrastructure of the machine they are running on.
Monsoon users now have access to Singularity, allowing them to run specific codes that were built in a container. Although Docker is not supported on Monsoon, Singularity can be used to import and convert Docker containers, allowing them to be run on Monsoon.
Basic Usage
You can download pre-made singularity images from the singularity hub website. In the following example, we will download and run a simple singularity image called singularity-hello-world.
[abc123@wind ~]$ singularity pull shub://346
Found image vsoch/singularity-hello-world:master
Downloading image... 928b4fc5dbe536cc8ba678eb5e37aca814d4d413.img.gz
Decompressing /home/mkg52/928b4fc5dbe536cc8ba678eb5e37aca814d4d413.img.gz
[abc123@wind ~]$ mv 928b4fc5dbe536cc8ba678eb5e37aca814d4d413.img hello.img
[abc123@wind ~]$ singularity run hello.img
Hello
[abc123@wind ~]$ singularity run hello.img from inside docker
Hello from inside docker
More examples can be found on the web.
Running Singularity with Slurm
Any Singularity image can also be used with Slurm to run jobs. Using the image downloaded in the previous example, we could submit a job array and pass the current array id number as a parameter to the Singularity container (see Job Arrays for more information). This is shown in the following code snippet:
#!/bin/bash
#SBATCH --job-name=singularity-test
#SBATCH --array=1-5
module load singularity
srun singularity run hello.img "$SLURM_ARRAY_TASK_ID"
Submitting the job and checking the output files shows that the “Hello” command was run with the inputs 1 through 5:
[abc123@wind ~]$ sbatch singularity_test.sh
Submitted batch job 320
[abc123@wind ~]$ ls slurm-*
slurm-320_1.out slurm-320_2.out slurm-320_3.out slurm-320_4.out slurm-320_5.out
[abc123@wind ~]$ cat slurm-*
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
If you require mpi support in your Singularity image, please note that the image must be specifically built with this functionality.
Converting Docker Images to Singularity Images
Singularity images cannot be created from scratch on Monsoon without root user permissions.
- If you need a docker image converted, there are two options available to you:
- Ask the staff to create one for you or contact us.
- Convert the docker image on your own machine and then upload it to Monsoon.
In the event you should choose option 2, please follow these instructions:
The following must be done on your personal computer, not Monsoon:
- Install Singularity using their instructions. IMPORTANT! Singularity is designed for Unix-based systems, so you must have access to either a Mac OSX or Linux system to install Singularity. The following instructions will assume a Linux operating system.
- Download and convert a docker image from Docker’s repository: Singularity allows you to create an image and then import/convert a Docker image from Docker’s online repository. For example, to create a Singularity image of 2GB and import/convert Docker’s latest Ubuntu image into the Singularity image you would do the following (you must be the root user):
[root@head images]# singularity create -s 2048 MyUbuntu.img
Creating a new image with a maximum size of 2048MiB...
Executing image create helper
Formatting image with ext3 file system
Done.
[root@head images]# ls
MyUbuntu.img
[root@head images]# singularity import MyUbuntu.img docker://ubuntu:latest
Cache folder set to /root/.singularity/docker
[[ Extraction output ommitted ]]
Bootstrap initialization
No bootstrap definition passed, updating container
Executing Prebootstrap module
Executing Postbootstrap module
Done.
[root@head images]# singularity exec MyUbuntu.img cat /etc/issue
Ubuntu 16.04.2 LTS \n \l
[root@head images]# Hello
You can see that the version of Ubuntu is displayed when we run this command note. You can browse available docker images on Docker’s Repository.