Dockerfile 找不到可执行脚本(没有那个文件或目录)
Dockerfile cannot find executable script (no such file or directory)
我正在编写 Dockerfile 以便为 Web 服务器(更准确地说是闪亮的服务器)创建映像。它运行良好,但它依赖于一个巨大的数据库文件夹 (db/
),它没有随包一起分发,所以我想在创建图像时通过 运行ning 相应的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/
下面,也会出现同样的错误。我不明白为什么。
您无法从 Dockerfile 在主机上执行代码。 RUN
命令在正在构建的容器内执行。您可以:
- 在 docker 容器内复制
preprocessing_files
并在容器内复制 运行 preprocessing.sh
(这会增加容器的大小)
- 创建一个
makefile
/build.sh
脚本,在执行 docker build
之前启动 preprocessing.sh
我正在编写 Dockerfile 以便为 Web 服务器(更准确地说是闪亮的服务器)创建映像。它运行良好,但它依赖于一个巨大的数据库文件夹 (db/
),它没有随包一起分发,所以我想在创建图像时通过 运行ning 相应的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/
下面,也会出现同样的错误。我不明白为什么。
您无法从 Dockerfile 在主机上执行代码。 RUN
命令在正在构建的容器内执行。您可以:
- 在 docker 容器内复制
preprocessing_files
并在容器内复制 运行preprocessing.sh
(这会增加容器的大小) - 创建一个
makefile
/build.sh
脚本,在执行docker build
之前启动
preprocessing.sh