2

我正在处理一个多级 docker 构建文件,试图将一个额外的 war 文件添加到我们的基础 tomcat 映像中。我在带有 Docker for Windows 2.3.0.4 版本的 Windows 10 工作站上本地运行它,它使用 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 .并构建输出。

mvn package注意:我在尝试“调试”发生了什么之后添加了 ls 命令

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 映像中包含输出时出了什么问题。

4

1 回答 1

2

这将完成这项工作:

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

于 2020-08-12T16:13:55.940 回答