Install RStudio Server Inside Docker Container in Linux

Install RStudio Server Inside Docker Container in Linux

RStudio is an integrated development environment for R programming language. RStudio Server allows accessing RStudio through web browser.

This tutorial explains how to install RStudio Server inside a Docker container in the Linux. Commands have been tested on Ubuntu.

Prepare environment

Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.

Install RStudio Server

Before starting, create directory for RStudio workspace:

sudo mkdir -p /opt/rstudio/workspace

Set rstudio user (ID: 1000) as owner for newly created directory:

sudo chown -R 1000:1000 /opt/rstudio

Note: it doesn't matter that rstudio user doesn't exist on host system. The rstudio user will be created in the container.

  • Host network

Run the following command to create a container for RStudio Server that uses host network:

docker run -d --name=rstudio --restart=always --network=host \
    -v /opt/rstudio/workspace:/home/rstudio/workspace \
    -e PASSWORD=pwd123 \
    rocker/rstudio
  • User-defined bridge network

User-defined bridge network can be used for listening on different port. By default, RStudio service is listening on port 8787. It can be changed with -p option.

docker network create app-net
docker run -d --name=rstudio --restart=always --network=app-net \
    -p 8080:8787 \
    -v /opt/rstudio/workspace:/home/rstudio/workspace \
    -e PASSWORD=pwd123 \
    rocker/rstudio

Note: don't forget to change user password.

Testing RStudio Server

Open a web browser and go to http://<IP_ADDRESS>:8787, where <IP_ADDRESS> is the IP address of the system. Log in to the web interface using rstudio username and password.

RStudio Server Inside Docker Container in Linux

Uninstall RStudio Server

To completely remove RStudio Server, remove its container:

docker rm --force rstudio

Remove RStudio Server image:

docker rmi rocker/rstudio

You can also remove RStudio workspace:

sudo rm -rf /opt/rstudio

If a user-defined bridge network was created, you can delete it as follows:

docker network rm app-net

Leave a Comment

Cancel reply

Your email address will not be published.