Running RStudio Server with R-4.2.2 with Docker

Last updated: 2023/02/28

Recently I have gotten several messages from users having problems with running RStudio Server with the latest R version (4.2.2) from The Rocker Project. The latest RStudio Server image is based on r-ver:4.2.2, which is based on ubuntu:jammy (Ubuntu 22.04). The RStudio Server image for r-ver:4.2.0 is based on ubuntu:focal (Ubuntu 20.04). Perhaps some users are having problems with the latest RStudio Server image because they are using an outdated OS and/or Docker version? Let's test this out!

Two users have provided me with their OS and Docker versions.

  • Ubuntu 18.04.6 and Docker version 20.10.12
  • Ubuntu 18:04.3 and Docker version 20.10.7

Let me try to replicate these environments by using an Amazon EC2 instance. Both users are using Bionic Beaver (Ubuntu 18.04) so I'll start an instance using this OS.

My Ubuntu version on the EC2 instance is:

cat /etc/os-release
# NAME="Ubuntu"
# VERSION="18.04.6 LTS (Bionic Beaver)"
# ID=ubuntu
# ID_LIKE=debian
# PRETTY_NAME="Ubuntu 18.04.6 LTS"
# VERSION_ID="18.04"
# HOME_URL="https://www.ubuntu.com/"
# SUPPORT_URL="https://help.ubuntu.com/"
# BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
# PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
# VERSION_CODENAME=bionic
# UBUNTU_CODENAME=bionic

sudo apt update

Now I'll look for the matching Docker deb files at the Docker download page and use it to install Docker.

wget https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/docker-ce-cli_20.10.12~3-0~ubuntu-bionic_amd64.deb
sudo apt install ./docker-ce-cli_20.10.12~3-0~ubuntu-bionic_amd64.deb

wget https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/containerd.io_1.4.10-1_amd64.deb
sudo apt install ./containerd.io_1.4.10-1_amd64.deb

wget https://download.docker.com/linux/ubuntu/dists/bionic/pool/stable/amd64/docker-ce_20.10.12~3-0~ubuntu-bionic_amd64.deb
sudo apt install ./docker-ce_20.10.12~3-0~ubuntu-bionic_amd64.deb

# create a docker group
sudo groupadd docker
# add the ubuntu user to the docker group
sudo usermod -aG docker ubuntu
logout

After logging back in, let's check whether Docker is working.

docker --version
# Docker version 20.10.12, build e91ed57

sudo systemctl list-units --type=service | grep -i docker
# docker.service                                 loaded active running Docker Application Container Engine

docker run hello-world
# Unable to find image 'hello-world:latest' locally
# latest: Pulling from library/hello-world
# 2db29710123e: Pull complete
# Digest: sha256:6e8b6f026e0b9c419ea0fd02d3905dd0952ad1feea67543f525c73a0a790fefb
# Status: Downloaded newer image for hello-world:latest
# 
# Hello from Docker!
# This message shows that your installation appears to be working correctly.
# 
# To generate this message, Docker took the following steps:
#  1. The Docker client contacted the Docker daemon.
#  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
#     (amd64)
#  3. The Docker daemon created a new container from that image which runs the
#     executable that produces the output you are currently reading.
#  4. The Docker daemon streamed that output to the Docker client, which sent it
#     to your terminal.
#
# To try something more ambitious, you can run an Ubuntu container with:
#  $ docker run -it ubuntu bash
#
# Share images, automate workflows, and more with a free # Docker ID:
#  https://hub.docker.com/
#
# For more examples and ideas, visit:
#  https://docs.docker.com/get-started/

Now that Docker is working, let's try running RStudio Server.

docker run --rm -ti -e PASSWORD=password -p 8889:8787 rocker/rstudio
# [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
# [s6-init] ensuring user provided files have correct perms...exited 0.
# [fix-attrs.d] applying ownership & permissions fixes...
# [fix-attrs.d] done.
# [cont-init.d] executing container initialization scripts...
# [cont-init.d] 01_set_env: executing...
# skipping /var/run/s6/container_environment/HOME
# skipping /var/run/s6/container_environment/PASSWORD
# skipping /var/run/s6/container_environment/RSTUDIO_VERSION
# [cont-init.d] 01_set_env: exited 0.
# [cont-init.d] 02_userconf: executing...
# [cont-init.d] 02_userconf: exited 0.
# [cont-init.d] done.
# [services.d] starting services
# TTY detected. Printing informational message about logging configuration. Logging configuration loaded from '/etc/rstudio/logging.conf'. Logging to 'syslog'.
# [services.d] done.

I enter rstudio/password on the login page.

I can log in and R seems to be working fine.

Now let's try mounting some directories onto the container so that we can save our work.

mkdir rmd

docker run --rm -ti -v /home/ubuntu/rmd:/home/rstudio -e PASSWORD=password -p 8889:8787 rocker/rstudio

I logged in and created a new RMarkdown file and saved it in /home/rstudio. After stopping the Docker container, I checked the contents of rmd.

ls -lrt rmd
# total 4
# -rw-r--r-- 1 ubuntu ubuntu 15 Feb 24 01:03 hello.Rmd

Summary

Initially I thought users were having problems because they were using an outdated OS and/or Docker version, but this doesn't look like the case since RStudio Server worked fine in a similar environment.

I got a GitHub issue regarding how I used to run RStudio Server, which was to use USERID and GROUPID environment variables. This was done because the files created in RStudio Server did not belong to the host user.

   -e USERID=$(id -u) \
   -e GROUPID=$(id -g) \

But it seems like the Rocker team (or the Docker team) have made changes, such that the files created using RStudio Server will now belong to the host user. Therefore, I think you can exclude those parameters from now on.

Update: 2023/02/28; if the two environment variables are removed, .libPaths() does not list /packages as the first directory in RStudio Server if you start a container in the following manner:

docker run \
   --name $container_name \
   --rm \
   -d \
   -p $port:8787 \
   -v ${package_dir}:/packages \
   -v ~/github/:/home/rstudio/work \
   -v ~/analysis/:/analysis \
   -e PASSWORD=password \
   -e USERID=$(id -u) \
   -e GROUPID=$(id -g) \
   $rstudio_image

Let me know if you have any other issues.

Print Friendly, PDF & Email



Creative Commons License
This work is licensed under a Creative Commons
Attribution 4.0 International License
.
6 comments Add yours
  1. Hi,

    I wanted to let you know that while trying to follow your blog I ran into issues on an m1 chip mac. Even the hello world example (docker run –rm -p 8787:8787 -e PASSWORD=password rocker/rstudio) would result in an error like
    “`
    Unable to find image ‘rocker/rstudio:latest’ locally
    latest: Pulling from rocker/rstudio
    docker: no matching manifest for linux/arm64/v8 in the manifest list entries.
    “`

    There is an open issue and I found that this comment was what helped me get rstudio installed in the end.
    https://github.com/rstudio/rstudio/issues/8809#issuecomment-1224983878

    Otherwise Id’ keep getting errors “could not connect to the R session on Rstudio server” and I couldn’t get pass the authentication window.

    Wanted to leave this as a comment in case others run into this issue

    1. Hi Rohail,

      thanks for leaving the useful comment! As you already figured out, you need to use Docker images built using the same CPU architecture as your host machine.

      Cheers,
      Dave

    1. Hi Charles!

      I’m well. How are you? I’m back in Japan, so please let me know if you’re visiting Tokyo. Otherwise I’ll let you know if I’m down south.

      Thanks for the comment and it’s good timing because I’ve been recently learning about Singularity. I’ll probably write a blog post about running RStudio Server using Singularity in the near future and will make use of your notes.

      Cheers,
      Dave

      1. Oh, I was just in Tsurumi 10 days ago for the matsuri of Ushioda-jinja ! Let’s keep in touch! Your blog is giving you my OIST address isn’t it ?

        1. You’re still doing the Tsurumi matsuri! Amazing! Yep, I got your email so let’s keep in touch!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.