HomeLab 6: Dockerized RStudio Server, packages, persistent storage and SSL certs
R is used together with Docker for Reproducible Research and isolated development environments. Apart from the transparency, portability, extensibility and reusability that Docker provides in these context, having RStudio Server accessible in the browser from anywhere is awesome.
My main aim for this post, and the next one about Shiny Server, is to have at my disposal two services that share some resources but remain separate for ease of maintenance.
I decided that the Shiny Server should be its separate image, but it will need to access the same user installed package library (library folder). This is where volumes come into play. Also, for easily transferring files (like R projects and scripts) to the container, bind mounts are need.
For R versions >=
4.0.0 you should use the
rocker-versioned2 images that are based on Ubuntu LTS.
To make matters even simpler, these images come prepackaged with important system dependencies and multiple sets of R packages. The images build upon one another by using the
rocker_scripts that come with each image.
We will use the
rocker/verse image. This image is large and provides many packages for convenience. For reference, here is the versioned stack from the Rocker Project for the
|Install R from source and set RSPM as default CRAN mirror|
|Adds RStudio Server|
|Adds tidyverse packages & devtools|
|Adds tex & publishing-related package|
1. Install Docker and Docker Compose
I provide a walkthrough on this in my HomeLab 3 blog post.
2. Bring RStudio Server container up
Created directories for volumes/bind mounts
sudo apt update sudo apt upgrade
cd $HOME cd Installs/ # make folders for volumes/bind mounts mkdir rstudio cd rstudio/ mkdir renv mkdir r-projects mkdir r-scripts mkdir shiny-apps
version: "3.6" services: rstudio: image: rocker/verse:latest container_name: rstudio restart: unless-stopped #env_file: .rstudio.env # can declare password in here if needed ports: - 8787:8787 environment: - PASSWORD=password # change this volumes: - type: volume source: rstudio target: /home/rstudio #volume: #no-copy: true - type: bind source: ./r-projects target: /home/rstudio/r-projects - type: bind source: ./r-scripts target: /home/rstudio/r-scripts - type: bind source: ./renv target: /home/rstudio/renv - type: bind source: ./shiny-apps target: /home/rstudio/shiny-apps - type: volume source: r_libs target: /usr/local/lib/R #volume: #no-copy: true volumes: r_libs: rstudio:
# move the docker-compose.yaml to rstudio/ # e.g. sudo mv /home/vncuser/docker-compose.yaml /home/claudiu/Installs/rstudio
Bring container up:
sudo docker compose up -d
Visit local host http://127.17.0.1:8787 or local IP (in my case http://192.168.0.2:8787). Log in with:
password(you should change this in the
3. Reverse Proxy RStudio Server
As outline in previous posts, I use Nginx Proxy Manager for reverse proxying. To add a Proxy Host, connect to the Administrator user of Nginxpm and do the following:
Hosts > Add Proxy Host
- Domain Names: rserv.psychlab.eu
- Scheme: http
- IP: 192.168.0.2
- Port: 8787
- Cache Assets: disabled
- Block Common Exploits: enabled
- Websockets Support: enabled
- Access List: Publicly Accessible
- SSL Certificate: *.psychlab.eu, psychlab.eu
- Force SSL: enabled
- HSTS Enabled: enabled
- HTTP/2 Support: enabled
- HSTS Subdomains: disabled
If all went well you can access RStudio Server by going to your subdomain (in my case its
4. Test RStudio Server with persitent storage
renv package in R:
Result in R:
renv::paths$library() #  "/home/rstudio/renv/library/R-4.2/x86_64-pc-linux-gnu" list.files("/home/rstudio/renv/") # character(0)
cd renv/ cat > test.txt
list.files("/home/rstudio/renv/") #  "test.txt"
sudo rm test.txt
New result in R:
list.files("/home/rstudio/renv/") # character(0)
- How to install R, R packages, RStudio and RStudio Server on Ubuntu Linux
- HomeLab 5: Docker install LimeSurvey and plugins, reverse proxy with Nginxpm and automate database backups
- HomeLab 4: Install and configure Nginx Proxy Manager with SSL Wildcard Certs
- HomeLab 3: Install and configure Apache Guacamole as Docker Container
- HomeLab 2: Web domain, subdomains and Dynamic DNS with Cloudflare API