Skip to content

Latest commit

 

History

History
95 lines (63 loc) · 3.43 KB

7.rstudio.md

File metadata and controls

95 lines (63 loc) · 3.43 KB

Building a basic RStudio image

<< Episode 6 | TOC | --


Objectives

This episode will provide an additional example of a Dockerfile, by using an R container.


Rocker

In the last example with Cellranger, we built upon a stock Linux distribution. This may be fine if you're installing only a few packages, but for larger applications it can get very complex and tedious to build everything from the ground up.

For exmaple, there is no reason we need to build R and Rstudio from scratch; Rocker provides a number of prebuilt RStudio images we can use and then build our own R workflows.

To begin, we'll cd to the episode7_rstudio_build directory:

cd bio-workshop-18/episode7_rstudio_build

Rstudio Dockerfile

The Dockerfile we'll work with is not of any particuar value...we're going to install several random packages. The point of it though is to illustrate several different ways to install R packages.

The first part installs several packages through Ubuntu's package mananger apt:

FROM rocker/tidyverse:3.5

RUN apt-get update -qq && apt-get -y --no-install-recommends install \
      autoconf \
      automake \
      g++ \
      gcc \
      gfortran \
      make \
      && apt-get clean all \
      && rm -rf /var/lib/apt/lists/*

Here we're using version 3.5 (as opposed to just the lastest version). Also, most R packages are going to need a compiler to build the packages, so we'll install the basic GNU compilers, along with some other build tools.

The apt-get clean and rm -rf commands remove all of the temporary files downloaded during installation that we no longer need. This helps minimize the size of the final image.

The next part sets up some R specific settings:

RUN mkdir -p $HOME/.R
COPY Makevars /root/.R/Makevars

Makevars is a file that R will read when compiling packages. The main thing in this file is that it adds some OpenMP compiler flags to help with performance (for those R packages that utilize it). We're using the COPY command to actually import Makevars from our host machine into the image (so it will always be with the image).

The final part shows several R installation methods:

 RUN Rscript -e "library('devtools')" \
       -e "install.packages('DEoptimR')" \
       -e "install.packages('http:https://cran.r-project.org/src/contrib/Archive/robustbase/robustbase_0.90-2.tar.gz', repos=NULL, type='source')" \
       -e "install.packages('BiocManager')" \
       -e "source('http:https://bioconductor.org/biocLite.R')" \
       -e "biocLite('BiocParallel')" \
       -e "BiocManager::install('scater)" \
       && rm -rf /tmp/downloaded_packages

We can install packages from CRAN with install.packages(), we can use Bioconductor packages with biocLite().


Conclusion

Dockerfiles are the recipes that permit to build containers from scratch. They have been used to build the containers you pull from Web repositories. If you cannot find a container with the package you need online, you can build your own by writing a new Dockerfile.


Best practices


<< Episode 6 | TOC | --