Hi,
I'm trying to optimize the dockerfile of a perfectly running shinyapp. I'd like to take advantage of docker's multistep build to avoid reinstalling all the dependencies each time I modify the app's code, but things aren't going as expected and after the RUN R CMD install /build/myapp
I get the following error: installing to library ‘/usr/local/lib/R/site-library’ ERROR: dependencies [all deps listed in the DESCRIPTION file on my app] are not available for package ‘myapp’
.
This is the dockerfile of the app, can you help me to figure out what's wrong with it?
FROM rocker/r-ver:4.4.1 AS base
RUN echo "\noptions(shiny.port=3838, shiny.host='0.0.0.0')" >> /usr/local/lib/R/etc/Rprofile.site
# system libraries of general use
RUN apt-get update -y && \
apt-get install -y \
pandoc \
pandoc-citeproc \
libcairo2-dev \
libxt-dev \
make \
zlib1g-dev \
libcurl4-openssl-dev \
libssl-dev \
git \
libicu-dev \
# tinytex
perl \
wget \
libfontconfig1 && \
# cleaning
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# pin renv version
ENV RENV_VERSION="1.0.7"
RUN R -q -e "options(warn=2); install.packages('remotes')"
RUN R -q -e "options(warn=2); remotes::install_version('renv', '${RENV_VERSION}')"
# install R dependencies
# do this before copying the app-code, to ensure this layer is cached
WORKDIR /build
COPY myapp/renv.lock /build/renv.lock
RUN mkdir -p /build/renv
COPY myapp/.Rprofile /build/.Rprofile
COPY myapp/renv/activate.R /build/renv/activate.R
COPY myapp/renv/settings.json /build/renv/settings.json
RUN mkdir /build/renv/.cache
ENV RENV_PATHS_CACHE /build/renv/.cache
RUN R -q -e 'options(warn=2); renv::restore()'
# install TinyTex and latex dependencies
ENV PATH="${PATH}:/root/bin"
ENV CTAN_REPO="https://mirror.ctan.org/systems/texlive/tlnet"
RUN wget -qO- "https://yihui.org/tinytex/install-bin-unix.sh" | sh && \
fmtutil-sys --all && \
tlmgr install \
koma-script \
graphics \
microtype \
tex-gyre \
fancyhdr \
lastpage \
booktabs
FROM base AS runtime
COPY --from=base /usr/local/lib/R/ /usr/local/lib/R/
COPY --from=base /root/.TinyTeX/ /root/.TinyTeX/
WORKDIR /build
COPY --from=base /build .
# install R code
COPY myapp /build/myapp
RUN R CMD INSTALL /build/myapp
RUN groupadd -g 1000 shiny && useradd -c 'shiny' -u 1000 -g 1000 -m -d /home/shiny -s /sbin/nologin shiny
USER shiny
EXPOSE 3838
CMD R -e "myapp::run_app()"
The structure of myapp
folder is:
myapp\
|- Dockerfile
|-...
|- myapp\
|- DESCRIPTION
|- renv.lock
|- app.R
|-...
|- renv\
|- R\
|- inst
|- tests\
|-...