为闪亮的应用程序构建Docker映像时出现R包依赖关系问题

时间:2020-05-17 14:29:22

标签: r docker shiny dockerfile

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

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"]

1 个答案:

答案 0 :(得分:2)

错误日志通常会告诉您问题所在。对于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