Help Building Rstan into Docker Container

I’m building an R Shiny applications that leverages RStan. I can get the model to run in the Shiny app from my local computer (MacOS BigSur 11.2.2 with R Studio 1.3.1093, R version 4.0.3). However when I compile my docker image, it fails to compile after about 800 seconds of work on the rstan package, with a non descript error code.

Here’s the error code that I see when building the docker image.
executor failed running [/bin/sh -c Rscript -e ‘remotes::install_github(“stan-dev/rstan”, ref = “develop”, subdir = “rstan/rstan”)’]: exit code: 1

Is there anything in the Dockerfile below that stands out to others as being incorrect for installing and using rstan?

The alpha release of this app us supposed to be QCed on Monday. I only received a working model about a 10 days ago, and so could use a hand!!

FROM rocker/r-ver:4.0.3
RUN apt-get update && apt-get install -y  git-core libcurl4-openssl-dev libgit2-dev libssh2-1-dev libicu-dev libpng-dev libudunits2-dev zlib1g-dev libgdal-dev libproj-dev libgeos-dev libssl-dev libxml2-dev make pandoc pandoc-citeproc sqlite3 libsqlite3-dev libnode-dev && rm -rf /var/lib/apt/lists/*
RUN echo "options(repos = c(CRAN = 'https://packagemanager.rstudio.com/all/latest'), download.file.method = 'libcurl')" >> /usr/local/lib/R/etc/Rprofile.site
RUN R -e 'install.packages("remotes")'

RUN Rscript -e 'remotes::install_version("glue",upgrade="never", version = "1.4.2")'
RUN Rscript -e 'remotes::install_version("processx",upgrade="never", version = "3.4.4")'
RUN Rscript -e 'remotes::install_version("htmltools",upgrade="never", version = "0.5.1.1")'
RUN Rscript -e 'remotes::install_version("pkgload",upgrade="never", version = "1.1.0")'
RUN Rscript -e 'remotes::install_version("attempt",upgrade="never", version = "0.3.1")'
RUN Rscript -e 'remotes::install_version("testthat",upgrade="never", version = "3.0.0")'
RUN Rscript -e 'remotes::install_version("shiny",upgrade="never", version = "1.6.0")'
RUN Rscript -e 'remotes::install_version("config",upgrade="never", version = "0.3")'
RUN Rscript -e 'remotes::install_github("Thinkr-open/golem@aaae5c8788802a7b4aef4df23691902a286dd964")'

RUN Rscript -e 'remotes::install_version("shinydashboard",upgrade="never", version = "0.7.1")'
RUN Rscript -e 'remotes::install_version("usmap",upgrade="never", version = "0.5.1")'
RUN Rscript -e 'remotes::install_version("rgeos",upgrade="never", version = "0.5-5")'
RUN Rscript -e 'remotes::install_version("tidyverse",upgrade="never", version = "1.3.0")'
RUN Rscript -e 'remotes::install_version("shinyWidgets",upgrade="never", version = "0.5.4")'
RUN Rscript -e 'remotes::install_version("leaflet",upgrade="never", version = "2.0.3")'
RUN Rscript -e 'remotes::install_version("sf",upgrade="never", version = "0.9-6")'
RUN Rscript -e 'remotes::install_version("DBI",upgrade="never", version = "1.1.0")'
RUN Rscript -e 'remotes::install_version("rpostgis",upgrade="never", version = "1.4.3")'
RUN Rscript -e 'remotes::install_version("ggplot2",upgrade="never", version = "3.3.2")'
RUN Rscript -e 'remotes::install_version("rgdal",upgrade="never", version = "1.5-18")'
RUN Rscript -e 'remotes::install_version("RSQLite",upgrade="never", version = "2.2.1")'
RUN Rscript -e 'remotes::install_version("shinyjs",upgrade="never", version = "2.0.0")'
RUN Rscript -e 'remotes::install_version("tigris",upgrade="never", version = "1.0")'
RUN Rscript -e 'remotes::install_version("sp",upgrade="never", version = "1.4-4")'
RUN Rscript -e 'remotes::install_version("RCurl",upgrade="never", version = "1.98-1.2")'
RUN Rscript -e 'remotes::install_version("DT",upgrade="never", version = "0.16")'
RUN Rscript -e 'remotes::install_version("rmarkdown",upgrade="never", version = "2.5")'
RUN Rscript -e 'remotes::install_version("knitr",upgrade="never", version = "1.30")'
RUN Rscript -e 'remotes::install_version("leafgl",upgrade="never", version = "0.1.1")'
RUN Rscript -e 'remotes::install_version("tidyr",upgrade="never", version = "1.1.2")'
RUN Rscript -e 'remotes::install_version("pool",upgrade="never", version = "0.1.6")'
RUN Rscript -e 'remotes::install_version("waiter",upgrade="never", version = "0.1.3")'

RUN Rscript -e 'remotes::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan")'

RUN mkdir /build_zone
ADD . /build_zone
WORKDIR /build_zone
RUN R -e 'remotes::install_local(upgrade="never")'
RUN rm -rf /build_zone
EXPOSE 3838
CMD  ["R", "-e", "options('shiny.port'=3838,shiny.host='0.0.0.0');Shiny_TOOL::run_app()"]

Disclaimer, I’m very new to Docker.

I don’t know if it’ll help you but here is an old Docker file, which I set up a while back.

I presume you’ve ran this in R line by line?

Actually, I found your work on your GitHub sleuthing around online. It helped a lot - thank you. It’s 3am in NY and now have working model based on used input data from within the docker container. The solution was to install rstan before the other dependencies on the initial build. Phew… thanks again.

1 Like

Please post your final docker file here (a link to it), so we all can learn new things :)

2 Likes

I’ve attached the current working Dockerfile below. This file will likely change as I’m rebuilding the app to leverage Boostrap4. The main difference will be fewer R libraries (I might also clean up the COPY statement, but I’m less worried about that right now). Happy to hear QC comments from anyone familiar with Docker. Happy rstaning!

FROM rocker/r-ver:4.0.3

RUN apt-get update \
	&& apt-get install -y --no-install-recommends \
  	apt-utils \
  	ed \
  	libnlopt-dev \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/

# Install rstan
RUN install2.r --error --deps TRUE rstan

RUN apt-get update && apt-get install -y  --no-install-recommends\
   git-core \
   libcurl4-openssl-dev \
   libgit2-dev \
   libssh2-1-dev \
   libicu-dev \
   libpng-dev \
   libudunits2-dev \
   zlib1g-dev \
   libgdal-dev \
   libproj-dev \
   libgeos-dev \
   libssl-dev \
   libxml2-dev \
   make pandoc \
   pandoc-citeproc \
   sqlite3 \
   libsqlite3-dev \
   libnode-dev \
   && rm -rf /var/lib/apt/lists/*


RUN echo "options(repos = c(CRAN = 'https://packagemanager.rstudio.com/all/latest'), download.file.method = 'libcurl')" >> /usr/local/lib/R/etc/Rprofile.site
RUN R -e 'install.packages("remotes")'
    
RUN Rscript -e 'remotes::install_version("glue",upgrade="never", version = "1.4.2")'
RUN Rscript -e 'remotes::install_version("processx",upgrade="never", version = "3.4.4")'
RUN Rscript -e 'remotes::install_version("htmltools",upgrade="never", version = "0.5.1.1")'
RUN Rscript -e 'remotes::install_version("pkgload",upgrade="never", version = "1.1.0")'
RUN Rscript -e 'remotes::install_version("attempt",upgrade="never", version = "0.3.1")'
RUN Rscript -e 'remotes::install_version("testthat",upgrade="never", version = "3.0.0")'
RUN Rscript -e 'remotes::install_version("shiny",upgrade="never", version = "1.6.0")'
RUN Rscript -e 'remotes::install_version("config",upgrade="never", version = "0.3")'
RUN Rscript -e 'remotes::install_github("Thinkr-open/golem@aaae5c8788802a7b4aef4df23691902a286dd964")'

RUN Rscript -e 'remotes::install_version("shinydashboard",upgrade="never", version = "0.7.1")'
RUN Rscript -e 'remotes::install_version("usmap",upgrade="never", version = "0.5.1")'
RUN Rscript -e 'remotes::install_version("rgeos",upgrade="never", version = "0.5-5")'
RUN Rscript -e 'remotes::install_version("tidyverse",upgrade="never", version = "1.3.0")'
RUN Rscript -e 'remotes::install_version("shinyWidgets",upgrade="never", version = "0.5.4")'
RUN Rscript -e 'remotes::install_version("leaflet",upgrade="never", version = "2.0.3")'
RUN Rscript -e 'remotes::install_version("sf",upgrade="never", version = "0.9-6")'
RUN Rscript -e 'remotes::install_version("DBI",upgrade="never", version = "1.1.0")'
RUN Rscript -e 'remotes::install_version("rpostgis",upgrade="never", version = "1.4.3")'
RUN Rscript -e 'remotes::install_version("ggplot2",upgrade="never", version = "3.3.2")'
RUN Rscript -e 'remotes::install_version("rgdal",upgrade="never", version = "1.5-18")'
RUN Rscript -e 'remotes::install_version("RSQLite",upgrade="never", version = "2.2.1")'
RUN Rscript -e 'remotes::install_version("shinyjs",upgrade="never", version = "2.0.0")'
RUN Rscript -e 'remotes::install_version("tigris",upgrade="never", version = "1.0")'
RUN Rscript -e 'remotes::install_version("sp",upgrade="never", version = "1.4-4")'
RUN Rscript -e 'remotes::install_version("RCurl",upgrade="never", version = "1.98-1.2")'
RUN Rscript -e 'remotes::install_version("DT",upgrade="never", version = "0.16")'
RUN Rscript -e 'remotes::install_version("rmarkdown",upgrade="never", version = "2.5")'
RUN Rscript -e 'remotes::install_version("knitr",upgrade="never", version = "1.30")'
RUN Rscript -e 'remotes::install_version("leafgl",upgrade="never", version = "0.1.1")'
RUN Rscript -e 'remotes::install_version("tidyr",upgrade="never", version = "1.1.2")'
RUN Rscript -e 'remotes::install_version("pool",upgrade="never", version = "0.1.6")'
RUN Rscript -e 'remotes::install_version("waiter",upgrade="never", version = "0.1.3")'


RUN mkdir /build_zone
ADD . /build_zone
WORKDIR /build_zone
COPY . /srv/shiny-server/App
RUN R -e 'remotes::install_local(upgrade="never")'
RUN rm -rf /build_zone
EXPOSE 3838
CMD  ["R", "-e", "options('shiny.port'=3838,shiny.host='0.0.0.0');shiny_TOOL::run_app()"]
2 Likes