简体   繁体   English

Docker 多阶段构建从前一阶段复制失败

[英]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.

相关问题 多阶段 Docker Build COPY 失败,找不到文件 - Multistage Docker Build COPY fails, file not found 来自多级 Dockerfiles 的 `npm build` 和 `COPY --from` 失败,并显示 `COPY failed: stat /mnt/data/docker/overlay2/xxxxx/merged/app/build - `npm build` and `COPY --from` from multistage Dockerfiles fails with `COPY failed: stat /mnt/data/docker/overlay2/xxxxx/merged/app/build 多阶段 Docker 构建不会复制从前一阶段创建的文件 - Multi-stage Docker build doesn't copy files created from the previous stage 在多阶段 docker build 中复制 ffmpeg bins - Copy ffmpeg bins in multistage docker build 多级构建上的 Docker COPY 不起作用 - Docker COPY on multistage build doens't working Docker多阶段构建在vue.js上失败 - docker multistage build fails on vue.js 多阶段构建无法从上一阶段复制文件 - Multi stage build can't COPY file from previous stage Docker 前一阶段的多阶段构建和安装/共享 - Docker multi-stage build and mounting/sharing from previous stage Docker 多级构建未将 arguments 传递到第二级 - Docker multistage build doesn't pass arguments to second stage 无法在多阶段 docker build 中从一个阶段复制到另一个阶段 - cannot copy from one stage to another in multi stage docker build
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM