# Singularity Introduction Singularity is an open source container platform designed to be simple, fast, and secure. Unlike Docker containers which requires root privileges to run containers, Singularity is designed for ease-of-use on shared multiuser systems and in high performance computing (HPC) environments. **Documentation:** https://docs.sylabs.io/guides/latest/user-guide/ ### Installation See https://docs.sylabs.io/guides/latest/user-guide/quick_start.html for latest installation guidelines. However the steps are as follows: * Update linux & install dependencies * Install go * Install and compile Singularity from github ------------------------------------------------------------------------ ### Using Pre-built Images Instead of reinventing the wheel, can see if an signularity image has already been created. A library of existing images can be found (https://cloud.sylabs.io/library). Can also search for containers of interest via command line: ``` singularity search tensorflow ``` Once you have found an image on interest can use the command: ``` singularity pull library://lolcow ``` You can also use the build command to download pre-built images from an external resource. When using build you must specify a name for your container like so: ``` singularity build ubuntu.sif library://ubuntu ``` ------------------------------------------------------------------------ ### Interacting with Images * **shell** command allows you to spawn a new shell within your container and interact with it as though it were a virtual machine. ``` singularity shell lolcow_latest.sif ``` * **Command Execution** execute a custom command within a container by specifying the image file. ``` singularity exec lolcow_latest.sif cowsay moo # Or: singularity exec library://lolcow cowsay 'Fresh from the library!' ``` ------------------------------------------------------------------------ ### Running a Container SingularityCE containers contain runscripts. These are user-defined scripts that define the actions a container should perform when someone runs it. To achieve this can either: * 1) Use **run** command. * 2) Call the container as though it was an executable. ``` # 1 singularity run lolcow_latest.sif # 2 ./lolcow_latest.sif ``` You can also pass arguments to the runscript of a container: ``` singularity run library://alpine echo "hello" ``` Also files on the 'host' are reachable from within containers. E.g. ``` $ echo "Hello from inside the container" > $HOME/hostfile.txt $ singularity exec lolcow_latest.sif cat $HOME/hostfile.txt Hello from inside the container ``` ----------------------------------------------------------------------------- ### Mounting Additional Directories to Container. You can specify additional directories to bind mount into your container with the **--bind** option. In this example, the data directory on the host system is bind mounted to the /mnt directory inside the container. ``` $ echo "Drink milk (and never eat hamburgers)." > /data/cow_advice.txt $ singularity exec --bind /data:/mnt lolcow_latest.sif cat /mnt/cow_advice.txt Drink milk (and never eat hamburgers). ``` **Expand this section later**