R的Dockerfile配置-无法加载某些软件包

时间:2019-02-01 14:49:42

标签: r docker

我正在尝试通过docker文件将R加载到我的docker容器中。某些R软件包无法安装,例如rvest。我还要同时安装NiFi和Python。这是我的dockerfile:

FROM apache/nifi

ADD run.sh .
COPY nifi-extracttext-nar-1.5.nar /opt/nifi/nifi-1.8.0/lib
USER root
RUN apt-get update
RUN apt-get install -y python3 python3-dev python3-pip
RUN pip3 install bs4
RUN pip3 install requests
RUN chmod 777 run.sh

# PROBLEM AREA (everything above works great)
RUN apt-get -y install r-base
RUN apt-get -y install libcurl4-openssl-dev
RUN apt-get install libcurl4-openssl-dev

#setup R configs

FROM r-base:latest
RUN Rscript -e "install.packages('tidyverse', repos = 'http://cran.us.r-project.org')"
RUN Rscript -e "install.packages('httr', repos = 'http://cran.us.r-project.org')"
RUN Rscript -e "install.packages('rvest', repos = 'http://cran.us.rproject.org')"

USER nifi

ENTRYPOINT ["./run.sh"]

问题点肯定是在安装R本身,以及我想要的软件包。格式化R软件包安装的正确方法是什么?我最初是从this link提取格式的,但是不确定Rscript是正确的。

rvest似乎是一个特别的痛点。

UDPDATE:

当我尝试在docker build / run之后运行脚本时,出现此错误:

Error in library(httr) : there is no package called ‘httr’
Execution halted

ERROR: dependency ‘openssl’ is not available for package ‘httr’
* removing ‘/usr/local/lib/R/site-library/httr’

为什么会这样???我已经通过docker安装了它。


这些是一些错误:

The downloaded source packages are in
'/tmp/RtmpykICxP/downloaded_packages'
Warning messages:
1: In install.packages("rvest", repos = "http://cran.us.r-project.org") :
installation of package 'openssl' had non-zero exit status
2: In install.packages("rvest", repos = "http://cran.us.r-project.org") :
installation of package 'xml2' had non-zero exit status
3: In install.packages("rvest", repos = "http://cran.us.r-project.org") :
installation of package 'httr' had non-zero exit status
4: In install.packages("rvest", repos = "http://cran.us.r-project.org") :
installation of package 'rvest' had non-zero exit status

并且:

ERROR: configuration failed for package ‘xml2’
* removing ‘/usr/local/lib/R/site-library/xml2’
ERROR: dependency ‘openssl’ is not available for package ‘httr’
* removing ‘/usr/local/lib/R/site-library/httr’
ERROR: dependencies ‘xml2’, ‘httr’ are not available for package ‘rvest’
* removing ‘/usr/local/lib/R/site-library/rvest’

并且:

ERROR: dependencies ‘xml2’, ‘httr’ are not available for package ‘rvest’

在通过终端爬网并构建映像之后,我发现了这些错误。

1 个答案:

答案 0 :(得分:1)

您需要为操作系统安装xml2openssl软件包:

RUN apt-get -y install xml2 openssl

请注意,-yapt-get install指定了'是',因此您可以删除

RUN apt-get install libcurl4-openssl-dev

与上一行一样。

您可能还想为R软件包安装依赖项,例如

RUN Rscript -e "install.packages('tidyverse', repos = 'http://cran.us.r-project.org', dependencies=TRUE)"

希望有帮助。