Data Science / DevOps / OpenShift / PaaS / Uncategorized

R using RStudio Server with OpenShift


To know R is to love R. RStudio Server is a popular IDE tool that makes the R experience even better. And OpenShift makes it even easier again. R is for Riki. This lab is another in the OpenShift MiniLabs series.



Let’s demonstrate hosting an RStudio Server instance as a container managed by OpenShift. Moreover, the guest account home directory is mapped to an external volume such that any installed packages are preserved on container restart.



Initial Attempt

This tutorial assumes you have completed the OpenShift MiniLabs installation procedure. Then refresh before continuing.

Repeat Attempt

To reset your environment to repeat this tutorial do the following:

$ cd ~/containersascode
$ ./oc-cluster-wrapper/oc-cluster up containersascode
$ oc login -u system:admin
$ oc delete persistentvolumeclaim rstudioguestclaim
$ oc delete persistentvolume rstudiovolume
$ oc login -u developer -p developer
$ oc delete project rstudio


This demonstration begins by creating a persistent volume that can be later claimed by a container instance. This step is something typically done by an Administrator.

Create the Persistent Volume

Replace $VOLUMEPATH below with your preferred host-path location, e.g. /Users/johndoe/oc/volumes

$ oc login -u system:admin

$ oc get pv
$ oc create -f - << EOF!
apiVersion: v1
kind: PersistentVolume
  name: rstudiovolume
    storage: 2Gi
    - ReadWriteOnce
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle
    path: $VOLUMEPATH
$ oc get pv

Create Project

Let’s create a project for our new application. The RStudio Server container needs some extra privileges so will assign that as follows:

$ oc login -u developer -p developer
$ oc new-project rstudio --display-name='RStudio Server' --description='RStudio Server' 
$ oc login -u system:admin
$ oc adm policy add-scc-to-user anyuid -z default

Create Application from Dockerfile

You can create an OpenShift container straight from a Docker file. Do the following for the pre-supplied Docker file that will build an RStudio Server instance on Centos:

$ oc login -u developer -p developer
$ wget
$ oc new-app . -l name='server' --name='server' 
$ oc deploy server --cancel 
$ oc expose service server

Claim the Storage

$ oc login -u developer -p developer 
$ oc project rstudio

$ oc set volume dc/server --add \
    --overwrite \
    --name=work \
    --type=persistentVolumeClaim \
    --mount-path=/home/guest \
    --claim-size=2Gi \
    --claim-name=rstudioguestclaim \

Build the Image

Make sure you are in the same directory as the Dockerfile. The first build attempt will take some time. You can observe progress from the Console at

$ oc login -u developer -p developer 
$ oc project rstudio
$ oc start-build server --from-dir=. 
$ oc status -v

Verify Lab Success

Once deployed, visit your new RStudio Server instance at using credentials guest/guest. Try and few R commands but more interestingly install a new package, e.g. plyr.

Now restart the container by scaling the pod down and up again at: . Then revisit the RStudio Console and verify the previously installed package remains by issuing the command installed.packages() inside the RStudio console.


Some users on  Chrome may encounter an “R Session Disconnected” problem after login to The cause of this error is undetermined but a workaround is to just use an alternate browser such as Firefox instead.

Check sites such as and  for more on RStudio Server. Managing R libraries in RStudio server is described at


4 thoughts on “R using RStudio Server with OpenShift

  1. Pingback: RStudio Server as a Docker Container | emergile

  2. Pingback: RStudio Server Fedora Installation | emergile

  3. Pingback: Registries and OpenShift | emergile

  4. Pingback: Apache Spark, RStudio Server, SparkR with OpenShift | emergile

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s