r - 使用 Dockerfile 安装 R 包
问题描述
我正在尝试使用 Dockerfile 安装 R 包。
我安装了图像Rocker/Rstudio。
Dockerfile 的内容是:
# Base image https://hub.docker.com/r/rocker/rstudio
FROM rocker/rstudio:latest
## Create directories
RUN mkdir -p /rstudio
RUN mkdir -p /rscripts
##Install R packages
RUN R -e "install.packages(c('rvest', 'jsonlite', 'data.table' ,'stringr'), repos = 'http://cran.us.r-project.org')"
然后我构建我docker build -t my_r_image .
的图像: 图像构建但未安装软件包,因为我收到此警告:
将软件包安装到“/usr/local/lib/R/site-library”(因为“lib”未指定)警告:无法访问存储库的索引 http://cran.us.r-project.org/src/contrib : 无法打开 URL ' http://cran.us.r-project.org/src/contrib/PACKAGES '
我尝试通过替换http://cran.us.r-project.org
,= 'http://cran.rstudio.com/')"
但我得到一个类似的错误,说它无法访问存储库的索引。
任何人都知道我做错了什么?
编辑1:请参阅下面的输出,当我这样做时:
.libPaths()
[1] "/usr/local/lib/R/site-library" "/usr/local/lib/R/library"
install.packages(c('rvest', 'jsonlite', 'data.table' ,'stringr'), repos = 'http://cran.us.r-project.org')
Warning in install.packages :
unable to access index for repository https://mran.microsoft.com/snapshot/2019-10-15/src/contrib:
cannot open URL 'https://mran.microsoft.com/snapshot/2019-10-15/src/contrib/PACKAGES'
Installing packages into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning in install.packages :
unable to access index for repository http://cran.us.r-project.org/src/contrib:
cannot open URL 'http://cran.us.r-project.org/src/contrib/PACKAGES'
Warning in install.packages :
packages ‘rvest’, ‘jsonlite’, ‘data.table’, ‘stringr’ are not available (for R version 3.6.1)
解决方案
奇怪的是,使用完全相同的 Dockerfile,我使用 rocker/tidyverse 存储库而不是 rocker/rstudio 安装软件包没有问题。有谁知道这是为什么?
推荐阅读
- coldfusion - 使用List从中间,第一个位置和最后一个位置删除元素
- excel - 动态重新定义 Excel 范围
- docker-compose - OCI 运行时执行失败:执行失败:container_linux.go:348:启动容器进程导致“没有这样的文件或目录”:未知
- linux - 100% 内核 CPU 终止与服务器的连接
- jquery - ajax 从 Spring Boot 获取 html 页面
- node.js - Alexa 音频播放器指令
- reactjs - 如何在反应中隐藏/显示特定组件
- assembly - 如何从字符串输入中删除逗号
- sql - 在 SQL Server 中创建递归函数
- java - 简单的 AsyncTasc - 更好的解决方案 - 防止内存泄漏