A Singularity image is an essential part of creating a reproducible container and, eventually, reproducible research. This section explains the steps to create a singularity definition file, build an image, and run a container. The two primary sources for further discussion and details include:
In order to build a singularity image, you need to have singularity installed on your system, and you need to have a root privilege to build an image. There are sufficient instructions to do that (for example, here). You can also use Sylab Remote Builder services.
The Definition File (CausalGPS_rstudio.def) is the recipe for building the image. Please note that we build it upon [rocker/rstudio:4.0.4] image. For more details about generating a Definition File, please refer to Singularity User Guide.
To build the image, download the Definition File (CausalGPS_rstudio.def) and run the following:
$ sudo singularity build CausalGPS_rstudio.sif CausalGPS_rstudio.def
Running the command will generate a Singularity image (CausalGPS_rstudio.sif). You can double-check the CausalGPS package version by running the image using the following command:
singularity run CausalGPS_rstudio.sif
This will result in the following format:
03 Feb 2022 07:54:45 PM UTC
Container was created Thu (ver: [1] ‘0.2.6.9000’) CausalGPS package installed
If you want to use R in a console, you can follow these steps:
singularity shell CausalGPS_rstudio.sif
and then run R.
> R Singularity
This will provide the following results and will activate R.
4.0.4 (2021-02-15) -- "Lost Library Book"
R version Copyright (C) 2021 The R Foundation for Statistical Computing
: x86_64-pc-linux-gnu (64-bit)
Platform
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.'license()' or 'licence()' for distribution details.
Type
R is a collaborative project with many contributors.'contributors()' for more information and
Type 'citation()' on how to cite R or R packages in publications.
'demo()' for some demos, 'help()' for on-line help, or
Type 'help.start()' for an HTML browser interface to help.
'q()' to quit R.
Type
>
Now, you can run an R command. For example:
> utils::packageVersion("CausalGPS")
# [1] ‘0.2.6.9000’
You can also open an RStudio session in your browser by following these steps mentioned in Rocker Project (Singularity).
-p run var-lib-rstudio-server
mkdir
'provider=sqlite\ndirectory=/var/lib/rstudio-server\n' > database.conf
printf
--bind run:/run,var-lib-rstudio-server:/var/lib/rstudio-server,database.conf:/etc/rstudio/database.conf CausalGPS_rstudio.sif rserver --www-address=127.0.0.1 singularity exec
Open your browser and enter this URL:
127.0.0.1:8787