Doug Fir
Doug Fir

Reputation: 21292

Install packages during build of rocker/tidyverse docker image

I am building a docker image using rocker/tidyverse.

My Dockerfile:

FROM rocker/tidyverse:4.0.4

COPY train.R /train.R
COPY install.R /install.R
COPY entrypoint.sh /entrypoint.sh

# pre install the packages during build
RUN Rscript install.R

Here's the install.r script from above:

install.packages('pacman')
pacman::p_load(lubridate, Metrics, foreach)

Also tried a variation of this with just install.packages(<packagename>) for each of the packages in the install.r script.

When I attempt to build I get an error message:

docker-compose build rtrain

Step 5/5 : RUN Rscript install.R
 ---> Running in 3ebf7ab0c227
Installing package into '/usr/local/lib/R/site-library'
(as 'lib' is unspecified)
Warning: unable to access index for repository https://packagemanager.rstudio.com/cran/__linux__/focal/2021-03-30/src/contrib:
  cannot open URL 'https://packagemanager.rstudio.com/cran/__linux__/focal/2021-03-30/src/contrib/PACKAGES'
Warning message:
package 'pacman' is not available for this version of R

If I remove RUN Rscript install.r from build but instead run the image and then exec into it, I am able to run it with just Rsctipt install.r. It's only during build that this happens.

On the page on the first url I linked to above there's a mention of script install2.r but I could not find any mention of this anywhere. The full blurb:

NOTES

  • do not use apt-get install r-cran-* to install R packages on this stack . The requested R version and all R packages are installed from source in the version-stable stack. Installing R packages from apt (e.g. the r-cran-* packages) will install the version of R and versions of the packages that were built for the stable debian release (e.g. debian:stretch ), giving you a second version of R and different packages. Please install R packages from source using the install.packages() R function (or the install2.r script), and use apt only to install necessary system libraries (e.g. libxml2 ). If you would prefer to install only the latest verions of packages from pre-built binaries using apt-get , consider using the r-base stack instead.

Underlining I did try modifying install.r to just be repeated rows of install.packages("lubridate") install.packages("Metrics") and install.packages("foreach") but the same error happens.

How can I install packages during build using this image?

Upvotes: 1

Views: 3477

Answers (1)

Doug Fir
Doug Fir

Reputation: 21292

Changing my version to 4.0.1 solved my problem:

FROM rocker/tidyverse:4.0.1

Then everything else the same, worked.

Upvotes: 1

Related Questions