Hello everyone,
I'm trying to build a dockerfile for my shinyapp. There are many libraries to install Shinyapp needs. That's why, you need to define all packages in second RUN layer one by one.
For example:
RUN R -e "install.packages(c('renv', 'shiny', 'tidyverse', ...), repos='https://cloud.r-project.org/')"
However, installing all packages can take too much time. I want to avoid wasting time and use renv in Dockerfile.
When using renv::restore(), it redownloads all packages instead of using them locally. I couldn't figure out how to arrange my dockerfile to avoid this issue.
I already installed all packages with renv in the project directory. How can I avoid redownloading and rebuilding the packages, when building a dockerfile?
FROM openanalytics/r-base
LABEL maintainer "Tobias Verbeke <tobias.verbeke@openanalytics.eu>"
# https://packagemanager.posit.co/client/#/repos/2/packages/A3
# system libraries of general use
RUN apt-get update && apt-get install -y \
sudo \
nano \
make \
automake \
pandoc \
pandoc-citeproc \
libicu-dev \
zlib1g-dev \
libcurl4-openssl-dev \
libssl-dev \
libfontconfig1-dev \
libfreetype6-dev \
libfribidi-dev \
libxml2-dev \
libharfbuzz-dev \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libglpk-dev \
libgmp3-dev \
libpq-dev \
libcairo2-dev \
libxt-dev \
libssh2-1-dev \
libssl1.1 \
libmpfr-dev
# install shiny packages
RUN R -e "install.packages(c('renv'), repos='https://cloud.r-project.org/')"
# Create Directory
RUN mkdir /root/Project
# copy the app to the image
COPY Project /root/Project
# copy all virtual environment files
COPY renv.lock /root/Project/renv.lock
COPY renv /root/Project/renv
COPY .Rprofile /root/Project/.Rprofile
EXPOSE 3838
CMD ["R", "-e", "renv::restore(); shiny::runApp('/root/Project')"]