0

I am developing an R package for a Shiny App and containerising this with Docker, and I've used Golem's add_dockerfile() command to create the Dockerfile below. (I've removed most of the dependencies for brevity.) Unfortunately, it doesn't build. Please could someone help?

Dockerfile

FROM rocker/r-ver:4.1.1
RUN apt-get update && apt-get install -y  git-core libcurl4-openssl-dev libgit2-dev libicu-dev libssl-dev libxml2-dev make pandoc pandoc-citeproc unixodbc-dev && rm -rf /var/lib/apt/lists/*
  RUN echo "options(repos = c(CRAN = 'http://cran.rstudio.com/'), download.file.method = 'libcurl', Ncpus = 4)" >> /usr/local/lib/R/etc/Rprofile.site
RUN R -e 'install.packages("remotes")'
RUN Rscript -e 'remotes::install_version("rlang",upgrade="never", version = "0.4.11")'
RUN Rscript -e 'remotes::install_version("glue",upgrade="never", version = "1.4.2")'

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');exampleApp::run_app()"

Error message

When I try to build this with docker build -t "test_image" ., I get the following error message:

=> ERROR [45/46] RUN R -e 'remotes::install_local(upgrade="never")'                                                                                        17.1s 
------
 > [45/46] RUN R -e 'remotes::install_local(upgrade="never")':
#49 0.499
#49 0.499 R version 4.1.1 (2021-08-10) -- "Kick Things"
#49 0.499 Copyright (C) 2021 The R Foundation for Statistical Computing
#49 0.499 Platform: x86_64-pc-linux-gnu (64-bit)
#49 0.499
#49 0.499 R is free software and comes with ABSOLUTELY NO WARRANTY.
#49 0.499 You are welcome to redistribute it under certain conditions.
#49 0.499 Type 'license()' or 'licence()' for distribution details.
#49 0.499
#49 0.499 R is a collaborative project with many contributors.
#49 0.499 Type 'contributors()' for more information and
#49 0.499 'citation()' on how to cite R or R packages in publications.
#49 0.499
#49 0.499 Type 'demo()' for some demos, 'help()' for on-line help, or
#49 0.499 'help.start()' for an HTML browser interface to help.
#49 0.499 Type 'q()' to quit R.
#49 0.499
#49 0.614 # Bootstrapping renv 0.14.0 --------------------------------------------------
#49 2.171 * Downloading renv 0.14.0 ... OK (downloaded source)
#49 3.624 * Installing renv 0.14.0 ... Done!
#49 16.84 * Successfully installed and loaded renv 0.14.0.
#49 16.97 * Project '/build_zone' loaded. [renv 0.14.0]
#49 17.03 > remotes::install_local(upgrade="never")
#49 17.04 Error in loadNamespace(x) : there is no package called ‘remotes’
#49 17.04 Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
#49 17.04 Execution halted

So it looks like the remotes package isn't found after the working directory is moved to /build_zone. Can anyone explain why this might be happening? I have tried a workaround and I managed to get the image to build but then when I tried to run it, it says that my package (exampleApp) is not found either. I don't have a good enough understanding of the Docker commands to know what's going on.

Thank you!

  • 1
    Hi, this is because you are using {renv} for your development. {remotes} needs to be listed in your renv.lock file, so that it is available when you restore the content. Whatever are packages installed before, {renv} assures a closed environment. You can have a look at this issue where not everything is solved, but almost: https://github.com/ThinkR-open/golem/issues/282 – Sébastien Rochette Nov 18 '21 at 15:26
  • 2
    Thank you so much! I already had {remotes} in the renv.lock file but the link you provided had what I needed. For me, this was to add renv/ and .Rprofile to the .dockerignore file - something I would never have figured out by myself. – Guy Brett-Robertson Nov 18 '21 at 16:56

1 Answers1

3

As you are using {renv}, You'll need to have {remotes} inside your renv.lock and/or inside your {renv} library to do remotes::install_local(upgrade="never") inside build_zone.

If you don't want it inside your dev environment, you can simply do:

RUN R -e 'renv::install("remotes");remotes::install_local(upgrade="never")'

Cheers,

Colin

Colin FAY
  • 4,849
  • 1
  • 12
  • 29