r - 在Docker Plumber中使用R预测包

标签 r docker dockerfile plumber

我正在尝试为使用预测库的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中添加预测时,容器的执行将停止:

During startup - Warning messages: 1: In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, : there is no package called ‘forecast’ 2: package ‘forecast’ in options("defaultPackages") was not found pr <- plumber::plumb(commandArgs()[4]); pr$run(host='0.0.0.0', port=8000) Error in library(forecast) : there is no package called ‘forecast’ Calls: ... -> source -> withVisible -> eval -> eval -> library In addition: Warning message: In readLines(file) : incomplete final line found on 'Plumber.R' Execution halted



知道是什么问题吗?与所有其他软件包/库一起使用时,只有预测会造成麻烦。
提前谢谢了

最佳答案

当我使用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=...'
--------------------------------------------------------------------

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

关于r - 在Docker Plumber中使用R预测包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48504153/

相关文章:

docker - 从计算机备份数据卷容器

tomcat - 如何将docker容器的IP地址动态映射到另一个容器

r - xlsx R 包覆盖以前的格式

r - 如何处理包含带逗号的文本行的 .csv 文件?

node.js - Docker Node App Postgres错误 “Connection terminated unexpectedly”

Docker-Compose:服务 "xxx"依赖于未定义的服务 "xxx":无效的 compose 项目

tomcat - 使用 Docker-compose 将文件复制到 Docker 容器中的 tomcat webapps 文件夹

git - 在远程 git 项目的 dockerfile 中添加依赖项以使缓存无效

r - data.frames R 列表列表中元素的平均值

R中data.table包中fread速度的原因