我正在研究一个多阶段docker构建文件,试图将一个额外的war文件添加到我们的基本tomcat镜像中。我正在Windows 10工作站上使用Docker for Windows 2.3.0.4在本地运行此版本,该版本使用Docker引擎19.03.12版
我原来的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
我想做的是从源代码构建psi-probe,并将war文件添加到此基本镜像中。到目前为止,这是我所拥有的
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
我可以运行docker build --target buildprobe -t buildprobe -f Dockerfile .
并构建输出。maven软件包和两个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
但是,当构建进入阶段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
对于正在开发的 Angular 应用程序,我也有类似的dockerfile。该文件的内容如下: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;"]
在此文件中,上一阶段的COPY
可以正常工作,并且图像会生成我只是不确定要从源代码构建psi-probe,然后将输出包含在我的tomcat图像中,出了什么问题。
最佳答案
这将完成工作:
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
您缺少r
关于docker - Docker多阶段构建在上一阶段的复制中失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63380253/