0

我正在为 Shiny App 开发一个 R 包并使用 Docker 将其容器化,并且我使用 Golem 的add_dockerfile()命令在下面创建了 Dockerfile。(为简洁起见,我删除了大部分依赖项。)不幸的是,它没有构建。请问有人可以帮忙吗?

Dockerfile

FROM rocker/r-ver:4.1.1
RUN apt-get update && apt-get install -y  git-core libcurl4-openssl-dev libgit2-dev libicu-dev libssl-dev libxml2-dev make pandoc pandoc-citeproc unixodbc-dev && rm -rf /var/lib/apt/lists/*
  RUN echo "options(repos = c(CRAN = 'http://cran.rstudio.com/'), download.file.method = 'libcurl', Ncpus = 4)" >> /usr/local/lib/R/etc/Rprofile.site
RUN R -e 'install.packages("remotes")'
RUN Rscript -e 'remotes::install_version("rlang",upgrade="never", version = "0.4.11")'
RUN Rscript -e 'remotes::install_version("glue",upgrade="never", version = "1.4.2")'

RUN mkdir /build_zone
ADD . /build_zone
WORKDIR /build_zone
RUN R -e 'remotes::install_local(upgrade="never")'
RUN rm -rf /build_zone
EXPOSE 3838
CMD R -e "options('shiny.port' = 3838,shiny.host='0.0.0.0');exampleApp::run_app()"

错误信息

当我尝试使用 构建它时docker build -t "test_image" .,我收到以下错误消息:

=> ERROR [45/46] RUN R -e 'remotes::install_local(upgrade="never")'                                                                                        17.1s 
------
 > [45/46] RUN R -e 'remotes::install_local(upgrade="never")':
#49 0.499
#49 0.499 R version 4.1.1 (2021-08-10) -- "Kick Things"
#49 0.499 Copyright (C) 2021 The R Foundation for Statistical Computing
#49 0.499 Platform: x86_64-pc-linux-gnu (64-bit)
#49 0.499
#49 0.499 R is free software and comes with ABSOLUTELY NO WARRANTY.
#49 0.499 You are welcome to redistribute it under certain conditions.
#49 0.499 Type 'license()' or 'licence()' for distribution details.
#49 0.499
#49 0.499 R is a collaborative project with many contributors.
#49 0.499 Type 'contributors()' for more information and
#49 0.499 'citation()' on how to cite R or R packages in publications.
#49 0.499
#49 0.499 Type 'demo()' for some demos, 'help()' for on-line help, or
#49 0.499 'help.start()' for an HTML browser interface to help.
#49 0.499 Type 'q()' to quit R.
#49 0.499
#49 0.614 # Bootstrapping renv 0.14.0 --------------------------------------------------
#49 2.171 * Downloading renv 0.14.0 ... OK (downloaded source)
#49 3.624 * Installing renv 0.14.0 ... Done!
#49 16.84 * Successfully installed and loaded renv 0.14.0.
#49 16.97 * Project '/build_zone' loaded. [renv 0.14.0]
#49 17.03 > remotes::install_local(upgrade="never")
#49 17.04 Error in loadNamespace(x) : there is no package called ‘remotes’
#49 17.04 Calls: loadNamespace -> withRestarts -> withOneRestart -> doWithOneRestart
#49 17.04 Execution halted

所以看起来在工作目录移动到 /build_zone 后找不到 remotes 包。谁能解释为什么会发生这种情况?我尝试了一种解决方法,并且设法构建了映像,但是当我尝试运行它时,它说我的包 ( exampleApp) 也找不到。我对 Docker 命令的理解不够好,无法知道发生了什么。

谢谢!

4

1 回答 1

1

当您使用{renv}时,您需要{remotes}在您的renv.lock和/或在您的{renv}库中执行remotes::install_local(upgrade="never")inside build_zone

如果您不希望它在您的开发环境中,您可以简单地执行以下操作:

RUN R -e 'renv::install("remotes");remotes::install_local(upgrade="never")'

干杯,

科林

于 2021-11-25T09:12:18.660 回答