使用 Dockerfile 安装 R 包

ML_*_*ast 7 r package docker dockerfile

我正在尝试使用 Dockerfile 安装 R 包。

\n\n

我安装了图像Rocker/Rstudio

\n\n

Dockerfile的内容是:

\n\n
# Base image https://hub.docker.com/r/rocker/rstudio\nFROM rocker/rstudio:latest\n\n## Create directories\nRUN mkdir -p /rstudio\nRUN mkdir -p /rscripts\n\n\n##Install R packages\nRUN R -e "install.packages(c(\'rvest\', \'jsonlite\', \'data.table\' ,\'stringr\'), repos = \'http://cran.us.r-project.org\')"\n
Run Code Online (Sandbox Code Playgroud)\n\n

然后我构建我的图像执行:docker build -t my_r_image .\n图像构建但软件包未安装,因为我收到此警告:

\n\n
\n

Installing packages into \xe2\x80\x98/usr/local/lib/R/site-library\xe2\x80\x99 (as \xe2\x80\x98lib\xe2\x80\x99 is\n unspecified) Warning: unable to access index for repository\n http://cran.us.r-project.org/src/contrib: cannot open URL\n \'http://cran.us.r-project.org/src/contrib/PACKAGES\'

\n
\n\n

I tried by replacing http://cran.us.r-project.org by = \'http://cran.rstudio.com/\')" but I get a similar error saying that it is unable to access index for repository.

\n\n

Anyone has an idea of what I am doing wrong?

\n\n

edit1: See below output I get when I do:

\n\n
.libPaths()\n    [1] "/usr/local/lib/R/site-library" "/usr/local/lib/R/library"     \n\ninstall.packages(c(\'rvest\', \'jsonlite\', \'data.table\' ,\'stringr\'), repos = \'http://cran.us.r-project.org\')\n        Warning in install.packages :\n          unable to access index for repository https://mran.microsoft.com/snapshot/2019-10-15/src/contrib:\n          cannot open URL \'https://mran.microsoft.com/snapshot/2019-10-15/src/contrib/PACKAGES\'\n        Installing packages into \xe2\x80\x98/usr/local/lib/R/site-library\xe2\x80\x99\n        (as \xe2\x80\x98lib\xe2\x80\x99 is unspecified)\n        Warning in install.packages :\n          unable to access index for repository http://cran.us.r-project.org/src/contrib:\n          cannot open URL \'http://cran.us.r-project.org/src/contrib/PACKAGES\'\n        Warning in install.packages :\n          packages \xe2\x80\x98rvest\xe2\x80\x99, \xe2\x80\x98jsonlite\xe2\x80\x99, \xe2\x80\x98data.table\xe2\x80\x99, \xe2\x80\x98stringr\xe2\x80\x99 are not available (for R version 3.6.1)\n
Run Code Online (Sandbox Code Playgroud)\n

ML_*_*ast 2

奇怪的是,使用完全相同的 Dockerfile,我使用 rocker/tidyverse 存储库而不是 rocker/rstudio 安装软件包没有任何问题。有人知道这是为什么吗?