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.

There are two methods of using Docker images for R sessions with RStudio Server Pro, Launcher, and Kubernetes:

  • Extending the base r-session Docker image

  • Building a custom r-session Docker image

Docker images can include versions of R and R packages that are already installed, which allows users to work within R sessions without installing and compiling packages in their home directory.

You can specify one or more Docker images that can be used for for R sessions and background jobs.

Extending the base r-session Docker image

You can extend the base r-session Docker images available on Docker Hub by adding R, R packages, or system packages.

Create a Dockerfile that inherits the base r-session image:

FROM rstudio/r-session:centos6-1.2.1256-3

ARG R_VERSION=3.5.2 # Install build dependencies RUN set -x && yum install -y epel-release make gcc gcc-c++ # Install R dependencies RUN set -x \ && yum update -y \ && yum install -y yum-utils \ && yum-builddep -y R # Install R from source RUN cd /opt && mkdir R && cd 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} # Install R packages RUN /opt/R/$R_VERSION/bin/R -e 'install.packages("devtools", repos="http://cran.us.r-project.org")' \ && /opt/R/$R_VERSION/bin/R -e 'install.packages("tidyverse", repos="http://cran.us.r-project.org")' \ && /opt/R/$R_VERSION/bin/R -e 'install.packages("shiny", repos="http://cran.us.r-project.org")' \ && /opt/R/$R_VERSION/bin/R -e 'install.packages("rmarkdown", repos="http://cran.us.r-project.org")' # Include R in PATH ENV PATH="/opt/R/$R_VERSION/bin:${PATH}"

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

docker build . -t <DOCKER-REGISTRY>/r-session:centos6-1.2.1256-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:centos6-1.2.1256-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:centos6-1.2.1256-3-custom
default-container-image=<DOCKER-REGISTRY>/centos6-1.2.1256-3-custom

Building a custom r-session Docker image

Create a Dockerfile that reproduces the default image:

FROM centos:7.6.1810

# Set arguments
ARG R_VERSION=3.5.2
ARG RSP_VERSION=1.2.1256-3

# Installs updates and dependencies
RUN set -x \
&& yum install epel-release -y \
&& yum install rrdtool libuser-devel \
libcurl-devel libxml2-devel openssl-devel -y

# R dependencies
RUN yum-builddep R -y

# Install R from source
RUN cd /opt && mkdir R && cd R \
&& curl -O 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

# Install R packages
RUN /opt/R/$R_VERSION/bin/R -e 'install.packages("devtools", repos="http://cran.us.r-project.org")'
RUN /opt/R/$R_VERSION/bin/R -e 'install.packages("tidyverse", repos="http://cran.us.r-project.org")'
RUN /opt/R/$R_VERSION/bin/R -e 'install.packages("shiny", repos="http://cran.us.r-project.org")'
RUN /opt/R/$R_VERSION/bin/R -e 'install.packages("rmarkdown", repos="http://cran.us.r-project.org")'

# Open RStudio Server Pro session port
EXPOSE 8788/tcp

# Prepare access for the NFS share
RUN chmod 777 /home

# Install RStudio Server Pro session components
RUN curl -O https://www.rstudio.org/download/latest/stable/session/centos6/rsp-session-centos6-${RSP_VERSION}.tar.gz
RUN mkdir -p /usr/lib/rstudio-server
RUN tar zxvf ./rsp-session-centos6-${RSP_VERSION}.tar.gz -C /usr/lib/rstudio-server/
RUN mv /usr/lib/rstudio-server/rsp-session*/* /usr/lib/rstudio-server/
RUN rm -rf /usr/lib/rstudio-server/rsp-session*
RUN rm -f ./rsp-session-centos6-${RSP_VERSION}.tar.gz

# Set the locale
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

Edit the Dockerfile as needed, keeping in mind that the resulting Dockerfile must include the following functionality to work with Launcher:

  • Expose port 8787 from the R session
  • Chmod the home directory to 777 permissions to work with NFS mounts
  • Include the RStudio Server Pro session components

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:centos7-1.2.1256-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:centos7-1.2.1256-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:centos7-1.2.1256-3-custom
default-container-image=<DOCKER-REGISTRY>/centos7-1.2.1256-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:centos6-1.2.1256-3
docker save r-session.tar

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

docker load r-session.tar
docker tag rstudio/r-session:centos6-1.2.1256-3 <DOCKER-REGISTRY>/r-session:centos7-r-session:centos6-1.2.1256-3
docker push <DOCKER-REGISTRY>/r-session:centos6-1.2.1256-3

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

Comments