1

我正在尝试为使用预测库的 R 脚本构建 docker 映像。我的 Dockerfile 看起来像这样:

    FROM r-base:latest

RUN mkdir -p /usr/local/src/myscripts
COPY ./Plumber.R /usr/local/src/myscripts
WORKDIR /usr/local/src/myscripts

RUN R -e 'install.packages("plumber")'
RUN R -e 'install.packages("forecast")'

EXPOSE 8000
ENTRYPOINT ["R", "-e", "pr <- plumber::plumb(commandArgs()[4]); pr$run(host='0.0.0.0', port=8000)"]
CMD ["Plumber.R"]

Plumber.R 非常简单,包含在第一行库(预测)中。没有预测,一切都很好,我可以运行容器。在上面的 dockerfile 和 Plumber.R 中添加预测时,容器的执行会停止:

启动期间 - 警告消息:1:在库中(包,lib.loc = lib.loc,character.only = TRUE,logical.return = TRUE,:没有名为“预测”的包 2:选项中的包“预测” ("defaultPackages") 未找到 pr <- plumber::plumb(commandArgs()[4]); pr$run(host='0.0.0.0', port=8000) 库中的错误(预测):没有名为'forecast'的包调用:... -> source -> withVisible -> eval -> eval -> library 另外:警告消息:在 readLines(file) 中:在 'Plumber.R' 上找到不完整的最后一行 执行停止

知道是什么问题吗?对于所有其他包/库,它只能预测会造成麻烦。提前谢谢了

4

1 回答 1

2

当我使用您的 Docker 文件构建容器时,我收到一些消息:

Warning messages:
1: In install.packages("forecast") :
  installation of package ‘curl’ had non-zero exit status
2: In install.packages("forecast") :
  installation of package ‘TTR’ had non-zero exit status
3: In install.packages("forecast") :
  installation of package ‘quantmod’ had non-zero exit status
4: In install.packages("forecast") :
  installation of package ‘tseries’ had non-zero exit status
5: In install.packages("forecast") :
  installation of package ‘forecast’ had non-zero exit status

这些消息的根源是以下错误:

------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libcurl was not found. Try installing:
 * deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
 * rpm: libcurl-devel (Fedora, CentOS, RHEL)
 * csw: libcurl_dev (Solaris)
If libcurl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------

因此,apt-get install libcurl4-openssl-dev在安装 R 包之前运行应该可以解决您的问题。

于 2018-01-29T16:30:29.207 回答