【发布时间】:2019-10-25 01:36:53
【问题描述】:
我正在编写 Dockerfile 以便为 Web 服务器(更准确地说是闪亮的服务器)创建映像。它工作得很好,但它依赖于一个巨大的数据库文件夹(db/),它没有随包一起分发,所以我想在创建映像时通过在 Dockerfile 中运行相应的脚本来完成所有这些预处理。
我希望这很简单,但我正在努力弄清楚我的文件在图像中的何处。
这个 repo 的结构如下:
Dockerfile
preprocessing_files
configuration_files
app/
application_files
db/
processed_files
这样app/db/ 不存在,而是在运行preprocessing_files 时创建并填充文件。
Dockerfile 如下:
# Install R version 3.6
FROM r-base:3.6.0
# Install Ubuntu packages
RUN apt-get update && apt-get install -y \
sudo \
gdebi-core \
pandoc \
pandoc-citeproc \
libcurl4-gnutls-dev \
libcairo2-dev/unstable \
libxml2-dev \
libxt-dev \
libssl-dev
# Download and install ShinyServer (latest version)
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
# Install R packages that are required
RUN R -e "install.packages(c('shiny', 'flexdashboard','rmarkdown','tidyverse','plotly','DT','drc','gridExtra','fitdistrplus'), repos='http://cran.rstudio.com/')"
# Copy configuration files into the Docker image
COPY shiny-server.conf /etc/shiny-server/shiny-server.conf
COPY /app /srv/shiny-server/
COPY /app/db /srv/shiny-server/app/
# Make the ShinyApp available at port 80
EXPOSE 80
CMD ["/usr/bin/shiny-server"]
以上文件运行良好如果 preprocessing_files 提前运行,所以app/application_files 可以成功读取app/db/processed_files。这个脚本如何在 Dockerfile 中运行?对我来说,直观的解决方案就是这样写:
RUN bash -c "preprocessing.sh"
在ADD 指令之前,但之后preprocessing_files 找不到。如果上面的指令写在ADD 和WORKDIR app/ 下面,也会发生同样的错误。我不明白为什么。
【问题讨论】:
标签: docker shiny-server