Skip to content

rohitfarmer/singularity-defs

Repository files navigation

Definition/Recipe Files for Singularity Containers

Some of the containers are available to download from https://cloud.sylabs.io/library/rohitfarmer

For feedback and collaboration write to me at [email protected]

Install Singularity on Linux

Singularity Version 3.4

Follow the instructions on https://sylabs.io/guides/3.4/user-guide/quick_start.html#quick-installation-steps

Building a Singularity Container

Readonly Container

To build a read-only SquashFS Singularity container on a local machine using a recipe/definition file.

sudo singularity build <container-name.sif> <Singularity.def>

To set a different temporary directory than the default /tmp.
sudo -E SINGULARITY_TMPDIR=/home/rohit/tmp singularity build <container.sif> <container.def>

Writable Sandbox.

To build a writable sandbox (essentially a folder) on a local machine using a recipe/definition file.

sudo singularity build --sandbox <sandbox-folder-name/> <Singularity.def>

Note: The advantage of building a writable sandbox is that it can be used to install and configure packages as you go, and once you are satisfied with the requirements, the sandbox can be converted into a read-only SquashFS container. To build a sandbox quickly, it's better to install a minimal set of packages via the definition file.

Install/Configure Packages in a Writable Sandbox

Once a writable sandbox is created to execute it to invoke the shell of the operating installed in the container in the "writable" mode. If the shell is not invoked in the "writable" mode, all the changes will be lost once you exit from the container environment.

sudo singularity shell --writable <sandbox-folder-name/>

Install packages as you would, for example, in Ubuntu from the command line.

Convert a Writable Sandbox to a Readonly Container

sudo singularity build <container-name.sif> <sandbox-folder-name/>

Execute a Container

Invoke a shell

The command below can be used for both read-only/writable containers/sandbox.

singularity shell <container-name.sif>

Note: By default, Singularity binds to your current working and home directory. Therefore, you do not need to do anything else to execute a script that is in your current working directory. It can also pull, for example, Vim settings from the .vimrc file in your home directory. Therefore, if Vim installed in the container, it can be used with the same settings from inside the container as it would from outside.

Execute a Command via Container

singularity exec <container-name.sif> <command>

For example: singularity exec <container-name.sif> Rscript --vanilla hello.R

Running Jupyter Notebooks from Within a Container

This section is for containers that have Jupyter notebook installed (e.g. cite-seq).

A generic command that should work on a personal computer. singularity exec container-name.sif jupyter notebook --no-browser --ip=127.0.0.1 --port=8888
Note: The IP address and the port number mentioned in the command are the jupyter defaults. They can be changed as per need.
Copy the URL generated by jupyter daemon and paste it in your browser; this should open Jupyter with the list of the files in your current working directory on the host computer.

Running with R as a Kernel

Sometimes if you already have an R kernel installed in your home directory, it conflicts with what you have inside the container. Therefore, it would require you to re-install the kernel specs in your home directory via the container.

singularity exec container-name.sif R --quiet --slave -e 'IRkernel::installspec()'

# Screen log.
# [InstallKernelSpec] Removing existing kernelspec in /home/user/.local/share/jupyter/kernels/ir
# [InstallKernelSpec] Installed kernelspec ir in /home/user/.local/share/jupyter/kernels/ir

Running on an HPC

  1. SSH to the HPC.
  2. Claim an interactive node.
  3. Navigate to your project directory. Singularity container should be in your project directory.
  4. singularity exec container-name.sif jupyter notebook --no-browser --ip='0.0.0.0'
  5. Keep the SSH session and Jupyter notebook session running. Copy the URL on your local browser.

Note: On some HPCs, you may have to initiate an additional SSH tunnel connecting your local machine to the interactive node on the HPC. In that case, follow some generic instructions here https://rohitfarmer.github.io/docs/docs/HPC/jupyter/ or ask your system administrator.

About

Definition (recipe) files for singularity containers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published