First Use of Docker

minor update below: troubleshooting with terminal interface.

So I started seeing things on twitter about using docker to run a standard version of R and with most the libraries I use on a regular basis already installed. I gave it a shot and now I need to sort this out even more – what a great tool! In addition, if you have a group of people using R on a project it should be quite simple to state the image to use or actually provide the image of R, Rstudio, and all the packages in one place.

Here I am not going to attempt to explain what Docker is – try youtube for that. I will simply say that Docker is similar to running a virtual machine but with far less overhead.

Steps to get Rstudio running Rocker.

  1. Install Docker
  2. Find the docker image that you want. I recommend using: rocker/geospatial. Though I will note that there is better documentation at the rocker/rstudio page.
  3. At the windows commandline (e.g. w. powershell) run the following (without the linebreaks or comments).
docker run --name my_Rstudio            ## name of your image 
           -d                               ## detached mode
           -v windows/folder:/home/rstudio  ## share a folder with docker image
           -p 8787:8787                     ## port to view rstudio on 
           -e PASSWORD=yourpasswordhere     ## set a password
           rocker/geospatial                ## the docker image to use
           
  1. Open your webrowser and goto http://localhost:8787/
  2. Login and use R
  3. Use the Docker GUI to start and stop the instance. Access it using the docker whale icon

Older Versions: R3.6 / GDAL / PROJ4

The coversion to PROJ6 seems to be causing some occasional grief. Some of the legacy PROJ4 projection details throw warnings when opening in a PROJ6 environment. Here is a docker install that provides earlier gdal and proj versions.

docker run --name myR_geo_3.6.1
           -d 
           -v windows/folder:/home/rstudio
           -p 8787:8787
           -e PASSWORD=pithypasswd
           -e ROOT=TRUE 
           rocker/geospatial:3.6.1

Troubleshooting with a terminal interface

A couple times now I have had my Dockerized Rstudio session lockup on me. Restarting the image, Docker, and the computer all failed to work and I was forced to create a new docker image. However, this took time as I had installed additional packages and pdf document creation usually required installation of numerous other libraries … lots of time

Here is a far easier solution:

  1. Open a bash shell (command line interface) for the Docker: docker exec -ti <DockerName> bash
  2. cd to /home/rstudio/.rstudio/sessions/active/ and delete all the files rm -R * This will loose data in the active session but it should get the rstudio server working again … Note: I never have Rstudio save my session environment. And as always save your work as you go!

Up next

  • Use QGIS and R together via a docker image. To get started see: Geocomputation in R in Docker.
  • Fine tuning – make my own image that includes the additional libraries I like to use.

Additional Resources

Colin Chisholm RPF
Colin Chisholm RPF
Forest Manager

Interested in forests and ecology