Docker image construction takes more than 4 hours due to packages

Hello,
I am on a project to deploy my application with shinyproxy, I cannot build the image because the packages contained in my shiny application cannot be installed. Construction starts but happens when the packages are installed it takes time, and finally I cancel the construction.
Please give me directions, thanks in advance
FROM openanalytics/r-base

MAINTAINER Tobias Verbeke

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 euler app

RUN apt-get update && apt-get install -y
libmpfr-dev

basic shiny functionality

RUN R -e “install.packages(c(‘shiny’,‘rmarkdown’,‘plotly’,‘shinyalert’,‘shinyWidgets’,‘tmap’,‘zoo’,‘tidyverse’,‘questionr’,‘tinytex’,‘data.table’,‘shinycssloaders’,‘sf’,‘readxl’’), repos=‘https://cloud.r-project.org/’)”

#RUN R -e “install.packages(c(‘plotly’), repos=‘https://cloud.r-project.org/’)”

install dependencies of the euler app

RUN R -e “install.packages(‘Rmpfr’, repos=‘https://cloud.r-project.org/’)”

copy the app to the image

RUN mkdir /root/emop
COPY emop /root/emop

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

EXPOSE 3838

CMD [“R”, “-e”, “shiny::runApp(’/root/emop’)”]

For anyone in the future suffering the same issue: Use an ubuntu base that allows you to take advantage of the incredible charitable work the Cran2Deb4Ubuntu team have done in precompiling R packages. Then install them with RUN apt-get update && apt-get install -y --no-install-recommends (a \ at the end of the line will let you split the command cleanly). The rocker/r-ubuntu:20.04 base has this repo enabled by default.

I also recommend multi-stage images. Build a base image with all of your “go-to” R packages that you’ll use for basically everything, then from there customise each image as needed. Whenever you make a change to the apt-get install section everything will need to be reinstalled, but if that’s split between multiple layers you will have a LOT less to redo.

1 Like

The hint is very helpful I altered the Dockerfile with this code:

RUN apt-get update && apt-get install -y --no-install-recommends \
    r-cran-rcpp \
    r-cran-shiny \
    r-cran-testthat

However this yields:

Unable to correct problems, you have held broken packages. The command '/bin/sh -c apt-get update && apt-get install -y --no-install-recommends     r-cran-rcpp     r-cran-shiny    r-cran-testthat' returned a non-zero code: 100

See Stackoverflow for a detailed description of the error message.

Thank you very much for your help!

Hello,

i had the same issue and i solve this with this ideas:

  1. Explicitly using cache for building the image
  2. I build the an image locally and push it to a public repository in dockerhub (you can try it magralo95/baseshinyapps).
1 Like