Search code examples
dockershinydockerfilercpp

Installing the Rcpp package in Docker leads to a freeze during the installation


I am installing an R Shiny app, but I am not able to run the installation anymore.

This is my Dockerfile

FROM openanalytics/r-base

# system libraries of general use
RUN apt-get update && apt-get install -y \
    sudo \
    pandoc \
    pandoc-citeproc \
    libcurl4-gnutls-dev \
    libcairo2-dev \
    libxt-dev \
    libssl-dev \
    libssh2-1-dev \
    libssl1.0.0

# system library dependency for the app
RUN apt-get update && apt-get install -y \
    libxml2-dev

RUN R -e "install.packages(c('data.table','janitor','snakecase'), repos='https://cloud.r-project.org/')"

RUN R -e "install.packages('https://cran.r-project.org/src/contrib/Archive/dplyr/dplyr_0.8.2.tar.gz', repos=NULL, type='source')"
RUN R -e "install.packages('https://cran.r-project.org/src/contrib/Archive/shiny/shiny_1.3.0.tar.gz', repos=NULL, type='source')"

# copy the app to the image
RUN mkdir /root/corona
COPY app /root/corona

COPY Rprofile.site /usr/lib/R/etc/

EXPOSE 3838

CMD ["R", "-e shiny::runApp('/root/corona', options = list(port = '3838'))"]

Building the image just freezes, always on this line:

* installing *source* package ‘R6’ ...
** package ‘R6’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (R6)
* installing *source* package ‘Rcpp’ ...
** package ‘Rcpp’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-ttHamR/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c api.cpp -o api.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I../inst/include/     -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-ttHamR/r-base-4.0.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c attributes.cpp -o attributes.o

Anyone who similar issue and can tell me why this happens?

I tried to install the package from source, tried another version, but it is always the same. It this a Docker related or package related problem?

Also tried to install it from there: install.packages("Rcpp", repos="https://rcppcore.github.io/drat")


Solution

  • If the compilation really fails, you may have too little RAM. I most often just commit my Dockerfiles and let hub.docker.com build them, but I also frequently test new ones or variations locally and they build just fine. In case you are on an underpowered cloud instance: Rcpp is C++ and does require a bit of RAM from the compiler. So don't try the cheapest 1 core, 512 mb RAM options.

    But you also have other options. As this is a system with apt, just install more of the CRAN packages as pre-made binaries: apt-get install r-cran-rcpp r-cran-data.table and so on.