Day-0: Setting up RStudio using Docker

In this tutorial, we'll walk you through how to set up RStudio, an open-source Integrated Development Environment (IDE) for R, using docker. Docker will allow us to run RStudio in a self-contained and reproducible environment.

Prerequisites

Before we begin, ensure that you have docker installed on your system. If you don't have docker installed, you can follow these tutorials based on your operating system:

Downloading the Docker Image

  1. Open your terminal (MAC, Linux) or PowerShell (Windows).

  2. Enter the following command to download the spriyansh29/sdac_2023 Docker image from Docker Hub:

docker pull spriyansh29/sdac_2023:latest
Have a coffee, it will take time!

Running the Docker Container (To verify the pull)

To start a container from the downloaded image, follow these steps:

  1. Input the following command in your terminal (MAC, Linux) only.

docker run -p 8787:8787 --rm -e USERID=$(id -u) -e USER=esr -e PASSWORD=biobam spriyansh29/sdac_2023:latest
  1. For Windows type the following in PowerShell,

docker run -p 8787:8787 --rm -e USER=esr -e PASSWORD=biobam spriyansh29/sdac_2023:latest

Here's what this command does:

  • -p 8787:8787 maps port 8787 of your machine to port 8787 inside the container.

  • -e USER=esr -e PASSWORD=biobam sets the environment variables for the username and password of the RStudio Server.

  • spriyansh29/sdac_2023:latest indicates the Docker image and its tag.

Once you have it up and running on your terminal, you should see some logs as follows,

Accessing RStudio Server

  1. Open your preferred web browser.

  2. In the address bar, type:

  3. http://localhost:8787
  4. You'll be prompted for a username and password. Input:

  • Username: esr

  • Password: biobam

Testing

To confirm that RStudio operates as expected, follow these steps:

  1. Inside RStudio's interface, navigate to File > New File > R Script

  2. In the newly created script, type:

print("Hello, World!")
  1. Click on "Run" or press Ctrl+Enter to execute the command.

  2. If "Hello, World!" appears in the console, your setup is successful!

Closing the running container

  • Return to the terminal where the Docker container is running.

  • Press Ctrl+C to stop the container or type docker rm -f $(docker ps -aq) in a terminal (MAC, Linux) or PowerShell (Windows).

Note: The command docker rm -f $(docker ps -aq) stops all running Docker containers. It's not recommended for shared systems.

Congratulations! You now have RStudio running in a Docker container. Let's now download the data.