Need to build and run a Docker image but don't have root access? No problem with Apptainer!

My group is moving towards a working paradigm where each project has a Docker image. This helps keep control of the environments for each project, as you know that operating systems and programming languages like R and Python undergo regular upgrades, which are mostly undesirable for long running data analytics projects. For example in the field of biomedical genomics, some projects can take up to 10 years between initiation and final publication, so having a stable and portable computing environment is crucial.

While this solution is fantastic if you have a workstation where you have free reign to use root/sudo permissions, many data analysts are restricted to using shared computing resources without root. There are some ways to mitigate these restrictions.

One approach is to make a Docker image on another computer and use Singularity or Udocker to pull and convert it to be run by non-root user.

But sometimes, users don't have access to another computer to build these images. Options for non-root users to build such images are very limited. Here I want to demonstrate how to achieve this using Apptainer.


Let's say you have a Dockerfile that describes all the dependancies of the project that looks like this:

FROM bioconductor/bioconductor_docker:RELEASE_3_19

# Update apt-get

RUN apt-get update \

        && apt-get upgrade -y \

        && apt-get install -y nano git libncurses-dev xorg openbox \

        && pip install magic-wormhole           \

        && apt-get clean \

        && rm -rf /var/lib/apt/lists/*

# Install CRAN packages

RUN Rscript -e 'install.packages(c("zoo","tidyverse","reshape2","gplots","MASS","eulerr","kableExtra","vioplot","pkgload","beeswarm"))'

# Install bioconductor packages

RUN Rscript -e 'BiocManager::install(c("DESeq2","fgsea","limma","topconfects","mitch"))'

# get a clone of the codes

RUN git clone https://github.com/markziemann/lung_brain.git

# Set the container working directory

ENV DIRPATH /myproject

WORKDIR $DIRPATH


The first step is to convert this into a format that is compatible with Singularity/Apptainer. For this, spython can convert it to a Singularity definition file. spython is available from pip3 package manager.

spython recipe Dockerfile > myproject.def

Next, the image can be built using Apptainer. Apptainer installation doesn't need root, but due to significant dependancies it would be better managed by the sysadmin, who would probably use a package manager like apt to simplify installation. Anyway assuming that it is installed properly, the image can be built like this:

apptainer build myproject.sif myproject.def

And once the image is built, you can launch the image and start interacting with it using bash. 

apptainer run --writable myproject.sif

or

apptainer shell --writable myproject.sif

After conducting the analysis, getting the results out of the container is the next challenge. By default apptainer does bind mount of the hosts home directory, so this part is relatively simple.

cp myresult.tsv /home/me/myproject/

----

Thanks to Shanon Loveridge for providing the key snippets of code for this post.

Popular posts from this blog

Data analysis step 8: Pathway analysis with GSEA

Uploading data to GEO - which method is faster?

Generating a custom gmt file for gene set analysis