运行 管道工 API 在 Docker 容器上
Running plumber API on Docker container
我想 运行 水管工 API Docker 集装箱。
我尝试了以下两个 dockerfiles:
第一个Docker文件
FROM rstudio/plumber
MAINTAINER Docker User <docker@user.org>
RUN R -e "install.packages('broom')"
RUN mkdir -p ~/application
# copy everything from the current directory into the container
COPY "/" "application/"
WORKDIR "application/"
# open port 80 to traffic
EXPOSE 80
# when the container starts, start the main.R script
ENTRYPOINT ["Rscript", "execute_plumber.R"]
第二个Docker文件:
FROM rocker/r-ver:4.0.2
# install the linux libraries needed for plumber
RUN apt-get update -qq && apt-get install -y \
libssl-dev \
libcurl4-gnutls-dev
# install plumber
RUN R -e "install.packages('plumber')"
RUN mkdir -p ~/application
# copy everything from the current directory into the container
COPY "/" "application/"
WORKDIR "application/"
# open port 80 to traffic
EXPOSE 80
# when the container starts, start the main.R script
ENTRYPOINT ["Rscript", "execute_plumber.R"]
两者都导致了以下错误:
* Downloading renv 0.12.0 from CRAN archive ... OK
* Installing renv 0.12.0 ... Done!
Successfully installed and loaded renv 0.12.0.
Error in library(plumber) : there is no package called ‘plumber’
Execution halted
对于第二个 Docker 文件,我还尝试安装不同的 linux 库,例如
git-core
libcurl4-openssl-dev
xml2 openssl
None 人提供了帮助。
我运行在 Azure 上安装它。有什么建议吗?
更新
在容器构建日志文件中,我可以清楚地看到 plumber
已成功安装。
> install.packages('plumber')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘curl’, ‘Rcpp’, ‘later’, ‘BH’, ‘rlang’, ‘glue’, ‘R6’, ‘stringi’, ‘jsonlite’, ‘webutils’, ‘httpuv’, ‘crayon’, ‘promises’, ‘sodium’, ‘swagger’, ‘magrittr’, ‘mime’, ‘lifecycle’
...
* DONE (plumber)
在此输出中:
> install.packages('plumber')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘curl’, ‘Rcpp’, ‘later’, ‘BH’, ‘rlang’, ‘glue’, ‘R6’, ‘stringi’, ‘jsonlite’, ‘webutils’, ‘httpuv’, ‘crayon’, ‘promises’, ‘sodium’, ‘swagger’, ‘magrittr’, ‘mime’, ‘lifecycle’
...
* DONE (plumber)
看起来包正在安装到 R 站点库中,但这里:
* Downloading renv 0.12.0 from CRAN archive ... OK
* Installing renv 0.12.0 ... Done!
Successfully installed and loaded renv 0.12.0.
Error in library(plumber) : there is no package called ‘plumber’
Execution halted
项目的 renv
自动加载器(通常是项目 .Rprofile
的一部分)正在 运行,这会将您的项目设置为使用私有库路径(与您的站点隔离)图书馆)。
我怀疑您可以通过重新组织 Dockerfile 中的命令来解决此问题;例如
FROM rocker/r-ver:4.0.2
# install the linux libraries needed for plumber
RUN apt-get update -qq && apt-get install -y \
libssl-dev \
libcurl4-gnutls-dev
# create the application folder
RUN mkdir -p ~/application
# copy everything from the current directory into the container
COPY "/" "application/"
WORKDIR "application/"
# open port 80 to traffic
EXPOSE 80
# install plumber
RUN R -e "install.packages('plumber')"
# when the container starts, start the main.R script
ENTRYPOINT ["Rscript", "execute_plumber.R"]
换句话说,确保在设置工作目录后调用 install.packages("plumber")
。
我想 运行 水管工 API Docker 集装箱。
我尝试了以下两个 dockerfiles:
第一个Docker文件
FROM rstudio/plumber
MAINTAINER Docker User <docker@user.org>
RUN R -e "install.packages('broom')"
RUN mkdir -p ~/application
# copy everything from the current directory into the container
COPY "/" "application/"
WORKDIR "application/"
# open port 80 to traffic
EXPOSE 80
# when the container starts, start the main.R script
ENTRYPOINT ["Rscript", "execute_plumber.R"]
第二个Docker文件:
FROM rocker/r-ver:4.0.2
# install the linux libraries needed for plumber
RUN apt-get update -qq && apt-get install -y \
libssl-dev \
libcurl4-gnutls-dev
# install plumber
RUN R -e "install.packages('plumber')"
RUN mkdir -p ~/application
# copy everything from the current directory into the container
COPY "/" "application/"
WORKDIR "application/"
# open port 80 to traffic
EXPOSE 80
# when the container starts, start the main.R script
ENTRYPOINT ["Rscript", "execute_plumber.R"]
两者都导致了以下错误:
* Downloading renv 0.12.0 from CRAN archive ... OK
* Installing renv 0.12.0 ... Done!
Successfully installed and loaded renv 0.12.0.
Error in library(plumber) : there is no package called ‘plumber’
Execution halted
对于第二个 Docker 文件,我还尝试安装不同的 linux 库,例如
git-core
libcurl4-openssl-dev
xml2 openssl
None 人提供了帮助。
我运行在 Azure 上安装它。有什么建议吗?
更新
在容器构建日志文件中,我可以清楚地看到 plumber
已成功安装。
> install.packages('plumber')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘curl’, ‘Rcpp’, ‘later’, ‘BH’, ‘rlang’, ‘glue’, ‘R6’, ‘stringi’, ‘jsonlite’, ‘webutils’, ‘httpuv’, ‘crayon’, ‘promises’, ‘sodium’, ‘swagger’, ‘magrittr’, ‘mime’, ‘lifecycle’
...
* DONE (plumber)
在此输出中:
> install.packages('plumber')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘curl’, ‘Rcpp’, ‘later’, ‘BH’, ‘rlang’, ‘glue’, ‘R6’, ‘stringi’, ‘jsonlite’, ‘webutils’, ‘httpuv’, ‘crayon’, ‘promises’, ‘sodium’, ‘swagger’, ‘magrittr’, ‘mime’, ‘lifecycle’
...
* DONE (plumber)
看起来包正在安装到 R 站点库中,但这里:
* Downloading renv 0.12.0 from CRAN archive ... OK
* Installing renv 0.12.0 ... Done!
Successfully installed and loaded renv 0.12.0.
Error in library(plumber) : there is no package called ‘plumber’
Execution halted
项目的 renv
自动加载器(通常是项目 .Rprofile
的一部分)正在 运行,这会将您的项目设置为使用私有库路径(与您的站点隔离)图书馆)。
我怀疑您可以通过重新组织 Dockerfile 中的命令来解决此问题;例如
FROM rocker/r-ver:4.0.2
# install the linux libraries needed for plumber
RUN apt-get update -qq && apt-get install -y \
libssl-dev \
libcurl4-gnutls-dev
# create the application folder
RUN mkdir -p ~/application
# copy everything from the current directory into the container
COPY "/" "application/"
WORKDIR "application/"
# open port 80 to traffic
EXPOSE 80
# install plumber
RUN R -e "install.packages('plumber')"
# when the container starts, start the main.R script
ENTRYPOINT ["Rscript", "execute_plumber.R"]
换句话说,确保在设置工作目录后调用 install.packages("plumber")
。