How to Add Cowsay to HPC Using Singularity

Keren Xu


 Recently, the USC’s Center for Advanced Research Computing (CARC) replaced its previous HPC cluster with the Discovery cluster. Very excitingly, it brings Environment Modules and Singularity to users. Singularity has already been installed on the Discovery cluster, so we only need to set up some environment variables to make sure it runs in our customized way. First, since Singularity uses caching strategy to make downloading images for build and pull faster and less redundant, to prevent it builds up docker layers, Cloud library images and metadata to clog up our $HOME directory, we set up an alternative folder for caching: export SINGULARITY_CACHEDIR="/scratch2/user/SINGULARITY_CACHEDIR/". Second, we also need to set up an alternative temporary directory for Singularity to build the squashfs filesystem and the directory should be large enough for the final resulting Singularity image. We can use export SINGULARITY_TMPDIR="/scratch2/user/SINGULARITY_TMPDIR/". Lastly, Singularity mounts our $HOME directory by default. If we want to access our files in the scratch system, we will need to change its default mounting directory by using export SINGULARITY_BINDPATH="/scratch2/user,/scratch/user". We can set as many directories here as we want. More detailed instruction about building environment is available here. All the commands above can be included in the .bashrc file. USC CARC also provides a great user guild here. Briefly, to pull an image from the cloud-based sources, we can use library:// for Singularity library, shub:// for Singularity hub, and docker:// for Docker hub. To run a Singularity container image, we can use the following commands: singularity shell, singularity exec, and singlarity run.

Now we know all the basics about Singularity and have set up its build environment. Let’s get started to pull a public image lolcow from Docker hub singularity pull docker://godlovedc/lolcow. Now a .sif image file lolcow_latest.sif is available in the cache folder. The final step is to add the command singularity run /path to your cache folder/lolcow_latest.sif to the .bashrc file. You will see the cowsay right after you source the .bashrc, and everytime you login to the discovery cluster or request a node.