Skip to content

Setting up a docker image to run R studio (For Windows users)

Sam Albers edited this page Aug 23, 2021 · 2 revisions

Setting up Docker Image to run RStudio on a Windows machine

Big thank-you to Colin Chisolm (UNBC/Aleza Lake Research forest) for helping me with the set up.

This process will set up the Windows Subsystem for Linux (WSL) on your Microsoft machine. This provides the ability to use Linux distributions directly within Windows.

Steps

  1. Set up WSL and download a linux platform (i.e. Ubuntu) I used these steps for the detailed version with Ubuntu 18.04 (installed on April 2020)

  2. Run the linux instance and assign a password and user name Assign UNIX username and password (step 6 of details above). For this example I used: UNIX username: rocker UNIX password: rocker

  3. Install Docker desktop and select the docker image to use. For geospatial analysis the rocker/georocker is recommended.

  4. Set up the file paths to link your local machine and virtual machine. This will mirror the links from your Microsoft machine to the linux side and will ensure that outputs are directed to correct location. This way you don’t need to transfer files back and forth as they both point to the same file location. When setting this up remember that filepaths for the Microsoft side you need to use the prefix mnt.

Open Ubuntu and create an image: ** if using BCGOV network need to use the Windows PowerShell as ADMIN (windows-x key).

The example below shows the commands to use based on linking the folder (d:/PEM_DATA/BEC_DevExchange_Work folder). Note you will need to adjust this to your needs.

Using the windows power shell

docker run --name rockergeo -d -v d:\PEM_DATA\BEC_DevExchange_Work:/home/rstudio/BEC_DevExchange_Work -e ROOT=TRUE -e PASSWORD=rocker -p 8787:8787 rocker/geospatial

Using Ubuntu command line and WSL - use the linux filepaths

docker run --name RockerG -d -v /mnt/c/workspace/:/home/rstudio/dworkspace/ -v /mnt/d/PEM_DATA/BEC_DevExchange_Work:/home/rstudio/BEC_DevExchange_Work/ -e ROOT=TRUE -e PASSWORD=rocker -p 8787:8787 rocker/geospatial

Note you can also map to multiple locations in this command if you want to link multiple folder locations.

If using the shell you will see this message Image Now you are all set up and ready to go!

5.To use RStudio To open an instance of RStudio open the docker desktop and select the instance you created. Alternatively type in a browser directly [http://localhost:8787]. You will be prompted for a user and password. Make sure to use the password you used for your unix passwork (i.e. step 1)

User = rstudio, password = rocker (*or whatever you selected as your unix password from step1)

Once in the RStudio session ensure you open the .Rproj file to make sure the filepath match. You should see the files structure mirrored in the files for the folder you pointed to above. If you don’t see any files (where there should be files – go back and check the line of code which specifies the linked locations). This can be very picky!

Other tips:

• To assess the command line in docker you can use the following commands in the Windows Powershell window

Docker ps (to see what is running)
Docker stop rockergeo     (or name of instance)
Docker run  (to run a docker instance)

Note this is preloaded with a number of packages. If you update more they will be retained in the instance, but if you need to delete the instance and start again you will need to reload all the pakages not already on the georocker instance. Note there is a way to create your own personal instance… yet to be worked out

If you need to update packages in the RStudio terminal tab type:

sudo apt-get install update