Difference between revisions of "Singularity Containers"

From IBERS Bioinformatics and HPC Wiki
Jump to: navigation, search
(Created page with "== What is Singularity == Singularity [https://www.sylabs.io/] is a container system that doesn't need root access. Containers are a set of applications and a minimal operati...")
 
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:
 
libraries and dependencies. This is helpful to reproducible science where we want somebody else to be able to recreate our results. They also allow us to run newer*/different operating systems than what is installed on the HPC.
 
libraries and dependencies. This is helpful to reproducible science where we want somebody else to be able to recreate our results. They also allow us to run newer*/different operating systems than what is installed on the HPC.
  
* = up to a point, the very latest operating systems (e.g. Ubuntu 18.04+) still don't work.
 
  
 
== Loading singularity ==
 
== Loading singularity ==
 +
 +
Singularity has now been renamed apptainer, but the singularity program is still available if you load the apptainer module.
  
 
Run the command (or add it to your submission script):
 
Run the command (or add it to your submission script):
  
     module load singularity
+
     module load apptainer
  
  
Line 89: Line 90:
 
* Create an account on Singularity Hub.
 
* Create an account on Singularity Hub.
 
* Add this repository to Singularity Hub and it will be automatically built by singularity hub and made available for download using the singularity pull command.
 
* Add this repository to Singularity Hub and it will be automatically built by singularity hub and made available for download using the singularity pull command.
 +
 +
== More Information ==
 +
 +
* [[:file:Containers.pdf|Presentation on containers]] from the July 2018 Bioinformatics workshop.
 +
* [https://www.sylabs.io/guides/2.5.1/user-guide Official Documentation]

Latest revision as of 16:33, 27 October 2022

What is Singularity

Singularity [1] is a container system that doesn't need root access. Containers are a set of applications and a minimal operating system bundled together in a single file. They are a good way to ensure that anyone running the software is using the exact same set of libraries and dependencies. This is helpful to reproducible science where we want somebody else to be able to recreate our results. They also allow us to run newer*/different operating systems than what is installed on the HPC.


Loading singularity

Singularity has now been renamed apptainer, but the singularity program is still available if you load the apptainer module.

Run the command (or add it to your submission script):

   module load apptainer 


Obtaining Containers

Singularity Hub [2] contains a number of premade containers which you can download and use. To download these run:

   singularity pull shub://<username>/<imagename>:<tag>  

e.g.

   singularity pull shub://SupercomputingWales/singularity_hub:base_image 

This will then download the file to <username>-singularity_hub-master-<image name>.simg

Running a shell in a container

The singularity shell command will run a shell inside the container. You can then execute any commands from software installed in the container. To do this run the command "singularity shell".

   singularity shell <image name>

e.g.

   singularity shell SupercomputingWales-singularity_hub-master-base_image.simg 

Running the container's default actions

Most containers specify a default command which they will run. The "singularity run" command will execute this.

   singularity run <image name>


Accessing the host file system from inside the container

   singularity shell -B /ibers/ernie/home:/home <imagename>

This will mount the directory /ibers/ernie/home from the host under /home in the container. Your own home directory will be under /home/<userid>. Note that accessing the ~ or ~<userid> directories won't work.

Writing your own containers

To make your own containers you'll probably have to install singularity on your own computer, as building a container requires root access.

This example takes an ubuntu 16.04 image as a base, then installs the program cowsay. This is done when the container is built. When the container is run it executes cowsay with the arguments given on the command line.


   bootstrap: docker
   From:ubuntu:16.04
   %help
       Example container for Cowsay
   %labels
       MAINTAINER IBERS Admin
   %environment
       #configure our locale, without this we'll get locale errors
       export LC_ALL=C
       #cowsay installs to /usr/games, but this isn't in the path by default
       export PATH=/usr/games:$PATH
   
   %post  
       apt-get update
       apt-get -y install cowsay
   %runscript
       cowsay $@


To build the container save the above example in a file called Singularity and run:

    sudo singularity build cowsay.simg Singularity

This will create an image file called cowsay.simg containing all the required software to run cowsay in an ubuntu 16.04 operating system.

Publishing a Container

  • Publish the Singularity file on Github.
  • Create an account on Singularity Hub.
  • Add this repository to Singularity Hub and it will be automatically built by singularity hub and made available for download using the singularity pull command.

More Information