[英]Docker Multistage Build Fails on copy from previous stage
I am working on a multistage docker build file in an attempt to add an additional war file to our base tomcat image.我正在开发一个多级 docker 构建文件,试图向我们的基础 tomcat 映像添加一个额外的 war 文件。 I am running this locally on a windows 10 workstation with Docker for Windows version 2.3.0.4 which uses docker engine version 19.03.12
I am running this locally on a windows 10 workstation with Docker for Windows version 2.3.0.4 which uses docker engine version 19.03.12
My original dockerfile looked like this我原来的 dockerfile 看起来像这样
FROM tomcat:9.0.21-jdk8-openjdk
RUN rm -rf /usr/local/tomcat/webapps/*
COPY logging.properties /usr/local/tomcat/conf
COPY tomcat-users.xml /usr/local/tomcat/conf
COPY jt400-jdk8-9.7.jar /usr/local/tomcat/lib
COPY mysql-connector-java-8.0.12.jar /usr/local/tomcat/lib
COPY ojdbc6.jar /usr/local/tomcat/lib
COPY hazelcast-all-3.12.jar /usr/local/tomcat/lib
COPY hazelcast-tomcat85-sessionmanager-1.1.3.jar /usr/local/tomcat/lib
COPY hazelcast-client.xml /usr/local/tomcat/lib
COPY applicationinsights-agent-2.5.1.jar /usr/local/tomcat/lib
What I want to do is build psi-probe from source and add the war file to this base image.我想要做的是从源代码构建 psi-probe 并将 war 文件添加到这个基础映像中。 Here is what I have thus far
这是我到目前为止所拥有的
FROM maven:3.6.3-openjdk-8 as buildprobe
RUN git clone https://github.com/psi-probe/psi-probe && cd psi-probe
WORKDIR /psi-probe
RUN mvn package && ls -l /psi-probe && ls -l /psi-probe/psi-probe-web/target
FROM tomcat:9.0.21-jdk8-openjdk
RUN rm -rf /usr/local/tomcat/webapps/*
COPY --from=buildprobe /psi-probe/psi-probe-web/taget/probe.war /usr/local/tomcat/webapps
I can run docker build --target buildprobe -t buildprobe -f Dockerfile.
我可以运行
docker build --target buildprobe -t buildprobe -f Dockerfile.
and the output is built.并构建了 output。
NOTE: I added the ls commands after
mvn package
in an attempt to "debug" what going on注意:我在
mvn package
之后添加了 ls 命令,试图“调试”正在发生的事情
The output from maven package and both ls commands is (truncated) output 来自 maven package 和两个 ls 命令是(截断)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for psi-probe 3.5.1-SNAPSHOT:
[INFO]
[INFO] psi-probe .......................................... SUCCESS [01:07 min]
[INFO] psi-probe-core ..................................... SUCCESS [01:53 min]
[INFO] psi-probe-rest ..................................... SUCCESS [ 5.945 s]
[INFO] psi-probe-tomcat7 .................................. SUCCESS [ 14.019 s]
[INFO] psi-probe-tomcat85 ................................. SUCCESS [ 13.403 s]
[INFO] psi-probe-tomcat9 .................................. SUCCESS [ 9.391 s]
[INFO] psi-probe-web ...................................... SUCCESS [ 39.060 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:30 min
[INFO] Finished at: 2020-08-12T14:39:19Z
[INFO] ------------------------------------------------------------------------
(ls -l /psi-probe)
...
-rw-r--r-- 1 root root 70248 Aug 12 14:29 pom.xml
drwxr-xr-x 1 root root 4096 Aug 12 14:36 psi-probe-core
drwxr-xr-x 1 root root 4096 Aug 12 14:38 psi-probe-rest
drwxr-xr-x 3 root root 4096 Aug 12 14:29 psi-probe-tomcat10
drwxr-xr-x 1 root root 4096 Aug 12 14:38 psi-probe-tomcat7
drwxr-xr-x 1 root root 4096 Aug 12 14:38 psi-probe-tomcat85
drwxr-xr-x 1 root root 4096 Aug 12 14:38 psi-probe-tomcat9
drwxr-xr-x 1 root root 4096 Aug 12 14:38 psi-probe-web
drwxr-xr-x 3 root root 4096 Aug 12 14:29 src
...
(ls -l /psi-probe/psi-probe-web/target)
drwxr-xr-x 2 root root 4096 Aug 12 14:38 classes
drwxr-xr-x 3 root root 4096 Aug 12 14:39 jspc
drwxr-xr-x 2 root root 4096 Aug 12 14:39 maven-archiver
drwxr-xr-x 7 root root 4096 Aug 12 14:39 probe
-rw-r--r-- 1 root root 27372423 Aug 12 14:39 probe.war
drwxr-xr-x 2 root root 4096 Aug 12 14:39 test-classes
-rw-r--r-- 1 root root 33350 Aug 12 14:39 webfrag.xml
However when the build gets to stage 1 ( FROM tomcat:9.0.21-jdk8-openjdk
) it fails on the COPY
command with但是,当构建进入第 1 阶段(
FROM tomcat:9.0.21-jdk8-openjdk
)时,它在COPY
命令上失败
COPY failed: stat /var/lib/docker/overlay2/81826a6b59d58818c342f1d5536489f4658be5e8557084ec572780aaf6ea19bc/merged/psi-probe/psi-probe-web/taget/probe.war: no such file or directory
I have a similar dockerfile for an angular app I am working on.我有一个类似的 dockerfile 用于我正在开发的 angular 应用程序。 This files reads as so:
该文件如下所示:
FROM node AS build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app/package.json
RUN npm install && npm install -g @angular/cli
COPY . /app
RUN ng build --output-path=dist
FROM nginx
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
In this file the COPY
from the previous stage works fine and the image builds在此文件中,上一阶段的
COPY
工作正常,并且图像构建
I'm simply not sure what is going wrong trying to build psi-probe from source and then including the output in my tomcat image.我只是不确定尝试从源代码构建 psi-probe 然后在我的 tomcat 图像中包含 output 出了什么问题。
This will do the job:这将完成这项工作:
FROM maven:3.6.3-openjdk-8 as buildprobe
RUN git clone https://github.com/psi-probe/psi-probe && cd psi-probe
WORKDIR /psi-probe
RUN mvn package && ls -l /psi-probe && ls -l /psi-probe/psi-probe-web/target
FROM tomcat:9.0.21-jdk8-openjdk
RUN rm -rf /usr/local/tomcat/webapps/*
COPY --from=buildprobe /psi-probe/psi-probe-web/target/probe.war /usr/local/tomcat/webapps
You were missing an r
您缺少
r
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.