I am looking into docker to distribute a shiny application that also requires RStudio. The primary goal is easy installation at hospitals under Windows. Everything that requires character input into black boxes will certainly fail during installation by non-IT people.

My previous attempts used vagrant, but installing vagrant alone proved to be a hurdle.

4 Solutions collect form web for “RStudio and Shiny in one dockerfile”

Interesting question, but I’m not sure I understand the advantage of having the shiny-server and the rstudio-server instances served from the same container.

Is the purpose so that the two containers share the same R libraries (e.g. so a package doesn’t need to be installed separately on each) or merely to have one docker container instead of two? Just having to run two docker commands instead of one doesn’t seem that onerous, but maybe I’m underestimating.

Sharing the underlying libraries seems like a valid objective though, and I don’t think there’s an ideal solution available yet.

I feel the most docker-esque solution would be to do this via container orchestration/compose tool as you mention. This is the usual way to combine separate services (e.g. web server and database) without building one on top of the other.

Unfortunately, the tooling for orchestration based on mapping volumes is not nearly as well developed as it is for mapping ports.

You can then use the the site.library from the rstudio container in place of that on the shiny container with a command like:

docker run --volumes-from rstudio -dP rocker/shiny

Unfortunately, this clobbers the site.library of the shiny container. To work around this, you’d want to mount the library of the rstudio container in a different place, but there’s no easy syntax for this like we already have with port links. It can be done though, see:

How to map volume paths using Docker's –volumes-from?

There’s an open thread on this issue in the rocker repo too.

The point of Docker, in general, is isolation of services so that they can be updated/changed without effecting others. My recommendation would be to use docker-compose, instead. Below is an example docker-compose yaml file that serves both rstudio and shiny on the same server at different subdomains using the incredibly useful docker-gen by Jason Wilder. All R docker images used below are courtesy of Rocker or more directly Rocker Docker Hub. These are very very reliable because, well, Dirk Eddelbeutel and Carl Boettiger made them. In this example I’ve also included some options for RStudio such as setting a user/pass and whether or not the user has root access. There are more instructions on using the Rocker RStudio image available on this wiki page:

Change the following:

your_user to your username on the server

SOME_USER to your desired RStudio username

SOME_PASS to your desired Rstudio password

*.DOMAIN.tld to your domain, don’t forget to add A records for your subdomains.

I have also developed a working docker for shiny server pro on centos (using shiny server pro temporary edition, valid 45 days only).

Somewhat unfortunately, there is no definite answer, it all depends on how much reusability you would be looking for and whether an upstream base image is well maintained. The is also images size tradeoff, more layers there are, bigger the resulting image gets.