为闪亮应用构建 docker 映像时的 R 包依赖项问题



我正在尝试为我的闪亮应用程序构建一个 docker 映像。 我的 docker 映像已"成功"构建,但无法在本地主机上启动。 检查映像构建过程中的日志,我看到如下错误消息:

ERROR: dependency ‘sf’ is not available for package ‘leafpop’
* removing ‘/usr/local/lib/R/site-library/leafpop’
..........
1: In install.packages(c("remotes", "shiny", "shinythemes", "shinydashboard",  :>
installation of package ‘units’ had non-zero exit status
2: In install.packages(c("remotes", "shiny", "shinythemes", "shinydashboard",  :
installation of package ‘sf’ had non-zero exit status
3: In install.packages(c("remotes", "shiny", "shinythemes", "shinydashboard",  :
installation of package ‘leafpop’ had non-zero exit status

看起来它有一些包依赖问题。 似乎包leafpop依赖于sf.不确定包装units...

我的问题是:

  1. 我应该如何修改我的 Dockerfile 来解决这个依赖问题?我想这也是一个普遍的问题。
  2. 我等了很长时间才完成图像构建过程。 我应该如何修改我的 Dockerfile,以便在某些软件包安装失败时停止构建过程?只是为了节省我的时间。

我的 Dockerfile 如下:

FROM rocker/shiny-verse
RUN apt-get update && apt-get install -y 
sudo 
gdebi-core 
pandoc 
pandoc-citeproc 
libcurl4-gnutls-dev 
libcairo2-dev 
libxt-dev 
libssl-dev 
libssh2-1-dev
RUN wget --no-verbose https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/VERSION -O "version.txt" && 
VERSION=$(cat version.txt)  && 
wget --no-verbose "https://s3.amazonaws.com/rstudio-shiny-server-os-build/ubuntu-12.04/x86_64/shiny-server-$VERSION-amd64.deb" -O ss-latest.deb && 
gdebi -n ss-latest.deb && 
rm -f version.txt ss-latest.deb
RUN R -e "install.packages(c('remotes', 'shinythemes','shinydashboard','shinyWidgets','shinyjs', 'rlang','scales','DT','lubridate', 'plotly',  'leaflet', 'leafpop', 'visNetwork', 'wordcloud2', 'arules'), repos='http://cran.rstudio.com/')"
RUN R -e "remotes::install_github('nik01010/dashboardthemes')"

COPY shiny-server.conf  /etc/shiny-server/shiny-server.conf
COPY /app /srv/shiny-server/
EXPOSE 80
COPY shiny-server.sh /usr/bin/shiny-server.sh
CMD ["/usr/bin/shiny-server.sh"]

错误日志通常会告诉您问题所在。对于units包,找不到系统库,即libudunits2.so.错误消息甚至告诉您如何安装它。

--------------------------------------------------------------------------------
Configuration failed because libudunits2.so was not found. Try installing:
* deb: libudunits2-dev (Debian, Ubuntu, ...)
* rpm: udunits2-devel (Fedora, EPEL, ...)
* brew: udunits (OSX)
If udunits2 is already installed in a non-standard location, use:
--configure-args='--with-udunits2-lib=/usr/local/lib'
if the library was not found, and/or:
--configure-args='--with-udunits2-include=/usr/include/udunits2'
if the header was not found, replacing paths with appropriate values.
You can alternatively set UDUNITS2_INCLUDE and UDUNITS2_LIBS manually.
--------------------------------------------------------------------------------

因为基础映像基于 debian 映像,所以请使用apt软件包,即libudunits2-dev。使用apt-get安装该包可修复此错误。

sf相关的错误如下:

* installing *source* package ‘sf’ ...
** package ‘sf’ successfully unpacked and MD5 sums checked
** using staged installation
configure: CC: gcc
configure: CXX: g++ -std=gnu++11
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘sf’
* removing ‘/usr/local/lib/R/site-library/sf’
cat: leafpop.out: No such file or directory
The downloaded source packages are in
‘/tmp/RtmpmvJxnC/downloaded_packages’
Warning message:
In install.packages(c("remotes", "shinythemes", "shinydashboard",  :
installation of one or more packages failed,
probably ‘sf’, ‘leafpop’

主要错误是找不到gdal-config或无法执行。经过一番谷歌搜索,我们发现libgdal-dev包提供了gdal-config.使用apt-get安装它可以解决这个问题。

将来,我建议通过尝试以交互方式构建容器来进行调试。然后在 Dockerfile 中编写正确的命令。交互式调试比迭代修改 Dockerfile 更容易。


关于你的第二个问题,install.packages接受一个Ncpus参数,它将并行编译包(如果包支持(。这可以显著缩短构建时间。

install.packages(... Ncpus=6)  # for example

最新更新