Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RStudio and Shiny in one dockerfile

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.

The rocker repository, has an RStudio and a Shiny , and for my own installation both work together. However, I would like to create a combined application for easier installation.

What is the recommended workflow? Start with RStudio, and manually add Shiny? Or merge the dockerfiles code from both Rockers, starting with r-base? Or use compose tool?

like image 586
Dieter Menne Avatar asked Mar 23 '15 14:03

Dieter Menne


1 Answers

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.

nginx1:
  image: nginx
  container_name: nginx
  ports:
  - "80:80"
  - "443:443"
  volumes:
    - /etc/nginx/conf.d
    - /etc/nginx/vhost.d
    - /usr/share/nginx/html
    - /home/your_user/services/volumes/proxy/certs:/etc/nginx/certs:ro

nginx-gen:
  links:
    - "nginx1"
  image: jwilder/docker-gen
  container_name: nginx-gen
  volumes:
    - /var/run/docker.sock:/tmp/docker.sock:ro
    - /home/your_user/services/volumes/proxy/templates/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
  volumes_from:
    - nginx1
  entrypoint: /usr/local/bin/docker-gen -notify-sighup nginx -watch -only-exposed -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf

rstudio:
  links:
    - "nginx1"
  image: rocker/hadleyverse
  container_name: rstudio
  ports:
    - "8787:8787"
  environment:
    - VIRTUAL_PORT=8787
    - ROOT=TRUE
    - VIRTUAL_HOST=rstudio.DOMAIN.tld
    - USER=SOME_USER
    - PASSWORD=SOME_PASS

shiny:
  links:
    - "nginx1"
  image: rocker/shiny
  container_name: shiny
  environment:
    - VIRTUAL_HOST=shiny.DOMAIN.tld
  volumes:
    - /home/your_user/services/volumes/shiny/apps:/srv/shiny-server/
    - /home/your_user/services/volumes/shiny/logs:/var/log/
    - /home/your_user/services/volumes/shiny/packages:/home/shiny/

It's trivial to add more services like a blog, for example, just follow the pattern or search the internet for a docker-compose version of your service and add it.

like image 195
Brandon Bertelsen Avatar answered Oct 23 '22 01:10

Brandon Bertelsen