Support

Using Docker images with RStudio Server Pro, Launcher, and Kubernetes

Follow
Launcher is a new feature of RStudio Server Pro 1.2 that is only available under named user licensing. RStudio Server Pro 1.2 without Launcher is available under existing server-based licensing. For questions about using Launcher with RStudio Server Pro, please contact sales@rstudio.com.

Overview

Docker images are used with RStudio Server Pro and Launcher to run R sessions and jobs across a Kubernetes cluster.

Docker images can include versions of R and R packages that are already installed, which allows users to work within R sessions and jobs without having to install and compile packages for each user.

You can use one or more Docker images in RStudio Server Pro and Launcher that can be used for for R sessions and background jobs. You can also enable an option for RStudio Server Pro users to specify arbitrary Docker images for their R sessions and jobs.

 

Layers to consider when using Docker images with RStudio Server Pro, Launcher, and Kubernetes

There are multiple layers to consider when building and using Docker images with RStudio Server Pro, Launcher, and Kubernetes.

Some of the layers are required for the image to function with RStudio Server Pro and Launcher, and some of the layers are optional and customizable:

  • Base OS or image (required)
  • RStudio Server Pro session components (required)
  • Required system packages (required)
  • One or more versions of R (required)
  • R packages (optional)
  • RStudio Professional Drivers (optional)
  • Other customizations (optional)

The sections below provide different options for using, customizing, and building Docker images for RStudio Server Pro and Launcher.

 

Options for using Docker images with RStudio Server Pro, Launcher, and Kubernetes

There are three options for using Docker images for with RStudio Server Pro, Launcher, and Kubernetes for R sessions and jobs:

  • Option A) Using the r-session-complete Docker image
  • Option B) Extending the r-session-complete Docker image

  • Option C) Building a custom r-session-complete Docker image

RStudio tests and verifies the functionality of RStudio Server Pro and Launcher using pre-built Docker images provided in Option A.

We recommend starting with the pre-built images during the install setup, configuration, and testing of RStudio Server Pro and Launcher.

After you verify the initial RStudio Server Pro and Launcher functionality, you can then choose to extend the pre-built images or build custom images to fit your needs using Options B and C. Note that custom Docker images are not supported by RStudio.

 

Option A) Using the r-session-complete Docker images

We recommend starting with the pre-built images during the install setup, configuration, and testing of RStudio Server Pro and Launcher.

Pre-built r-session-complete images are available from the rstudio/r-session-complete repository on Docker Hub:

https://hub.docker.com/r/rstudio/r-session-complete

  • rstudio/r-session-complete:centos7-1.2.1335-1-r-3.5.3
  • rstudio/r-session-complete:bionic-1.2.1335-1-r-3.5.3

You can use these image references in the container-images and default-container-image setting in the Launcher profiles configuration file (default /etc/rstudio/launcher.kubernetes.profiles.conf).

You will need to ensure that the Kubernetes worker nodes have the ability to pull images from the online Docker Hub registry, or refer to the steps in the "Using Docker images in an offline environment section" below to download and use the images in an offline environment.

These images include the following layers:

  • Base OS (CentOS 7 or Ubuntu 18.04)
  • Required system packages
  • RStudio Server Pro session components
  • One version of R
  • R packages (devtools, tidyverse, shiny, and rmarkdown)
  • RStudio Professional Drivers

 

Option B) Extending the r-session-complete Docker image

You can extend the r-session-complete Docker images by adding R, R packages, or system packages.

Create a Dockerfile that inherits the r-session-complete image and adds system packages, additional versions of R, and additional R packages.

Example 1: Adding R packages to the r-session-complete image:

FROM rstudio/r-session-complete:centos7-1.2.1335-1-r-3.5.3

# Install R packages ----------------------------------------------------------#

RUN /opt/R/${R_VERSION}/bin/R -e 'install.packages("plumber", repos="http://cran.us.r-project.org")' && \
    /opt/R/${R_VERSION}/bin/R -e 'install.packages("dbplyr", repos="http://cran.us.r-project.org")' && \
    /opt/R/${R_VERSION}/bin/R -e 'install.packages("shinydashboard", repos="http://cran.us.r-project.org")'

Example 2: Adding system packages to the r-session-complete image:

FROM rstudio/r-session-complete:centos7-1.2.1335-1-r-3.5.3

# Install additional system packages ------------------------------------------#

RUN yum update -y && \
    yum install -y \
    package1 \
    package2 && \
    yum clean all

Example 3: Adding another version of R to the r-session-complete image:

FROM rstudio/r-session-complete:centos7-1.2.1335-1-r-3.5.3

ARG R_VERSION=3.4.4

# Install R -------------------------------------------------------------------#

RUN sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list && \
    apt-get update -y && \
    DEBIAN_FRONTEND=noninteractive apt-get build-dep -y r-base

RUN mkdir -p /opt/R && \
    cd /opt/R && \
    wget https://cran.r-project.org/src/base/R-3/R-${R_VERSION}.tar.gz && \
    tar zxvf R-${R_VERSION}.tar.gz && \
    cd R-${R_VERSION}  && \
    ./configure --prefix=/opt/R/${R_VERSION} --enable-memory-profiling --enable-R-shlib --with-blas --with-lapack && \
    make && \
    make install && \
    rm -rf /opt/R/R-${R_VERSION}.tar.gz && \
    rm -rf /opt/R/R-${R_VERSION}

ENV PATH="/opt/R/${R_VERSION}/bin:${PATH}"

Once you've made additions to the r-session-complete image, you can run the following command to build a custom Docker image with your additions:

docker build . -t <DOCKER-REGISTRY>/r-session-complete:centos7-1.2.1335-1-r-3.5.3-custom

where <DOCKER-REGISTRY> is the name or URL of your Docker registry.

Push the image to a Docker registry that is accessible from the worker nodes in the Kubernetes cluster.

docker push <DOCKER-REGISTRY>/r-session-complete:centos7-1.2.1335-1-r-3.5.3-custom

Update the Launcher profiles configuration file to point to the custom Docker image (default /etc/rstudio/launcher.kubernetes.profiles.conf):

container-images=<DOCKER-REGISTRY>/r-session-complete:centos7-1.2.1335-1-r-3.5.3-custom
default-container-image=<DOCKER-REGISTRY>/centos7-1.2.1330-2-r-3.5.3-custom

Note that you can specify multiple container-images that can be selected by the RStudio Server Pro users when starting new R sessions or jobs.

 

Option C) Building a custom r-session-complete Docker image

If you need to build the Docker images yourself, use a different base OS, or otherwise build the Docker image yourself, you can use a custom Docker image by starting with the Dockerfile for r-session-complete.

Create a Dockerfile that reproduces the default image using the example Dockerfiles from the sol-eng/r-session-complete repository on GitHub:

Edit the Dockerfile as needed, and note that the resulting Dockerfile must include the following contents to work with Launcher:

  • Base OS
  • Required system packages
  • RStudio Server Pro session components (with port 8787 exposed)
  • One or more versions of R

Run the following command to build a custom Docker image and install the additional system packages and R packages:

docker build . -t <DOCKER-REGISTRY>/r-session-complete:centos7-1.2.1335-1-r-3.5.3-custom

where <DOCKER-REGISTRY> is the name or URL of your Docker registry.

Push the image to a Docker registry that is accessible from the worker nodes in the Kubernetes cluster.

docker push <DOCKER-REGISTRY>/r-session-complete:centos7-1.2.1335-1-r-3.5.3-custom

Update the Launcher profiles configuration file to point to the custom Docker image (default /etc/rstudio/launcher.kubernetes.profiles.conf):

container-images=<DOCKER-REGISTRY>/r-session-complete:centos7-1.2.1335-1-r-3.5.3-custom
default-container-image=<DOCKER-REGISTRY>/centos7-1.2.1330-2-r-3.5.3-custom

 

Using Docker images in an offline environment

If you are using RStudio Server Pro and Launcher in an environment that does not have network access to pull images from Docker Hub, you can pull the image, save it to disk, move it to the offline environment, load the image, tag the image, and push it to a Docker registry that is accessible from the worker nodes in the Kubernetes cluster.

In the environment with access to Docker Hub, run the following commands:

docker pull rstudio/r-session-complete:centos7-1.2.1335-1-r-3.5.3
docker save r-session-complete.tar

Move the tar file to the offline environment, then run the following commands:

docker load r-session-complete.tar
docker tag rstudio/r-session-complete:centos7-1.2.1335-1-r-3.5.3 <DOCKER-REGISTRY>/r-session-complete:centos7-1.2.1330-2-r-3.5.3
docker push <DOCKER-REGISTRY>/r-session-complete:centos7-1.2.1330-2-r-3.5.3

where <DOCKER-REGISTRY> is the name or URL of your Docker registry.

Comments