如题,mvn package之后,想把war拷贝到tomcat,一直失败。。。
从日志看,打包是成功的:
[2021-11-10 18:54:23] [INFO] Packaging webapp [2021-11-10 18:54:23] [INFO] Assembling webapp [nr-engine] in [/nr-engine/target/nr-engine] [2021-11-10 18:54:23] [INFO] Processing war project [2021-11-10 18:54:23] [INFO] Copying webapp webResources [/nr-engine/src/main/webapp] to [/nr-engine/target/nr-engine] [2021-11-10 18:54:23] [INFO] Copying webapp resources [/nr-engine/src/main/webapp] [2021-11-10 18:54:23] [INFO] Building war: /nr-engine/target/nr-engine.war [2021-11-10 18:54:23] [INFO] ------------------------------------------------------------------------ [2021-11-10 18:54:23] [INFO] BUILD SUCCESS [2021-11-10 18:54:23] [INFO] ------------------------------------------------------------------------ [2021-11-10 18:54:23] [INFO] Total time: 01:12 min [2021-11-10 18:54:23] [INFO] Finished at: 2021-11-10T10:54:23Z
但是,拷贝不成功:
[2021-11-10 18:54:30] Step 13/15 : COPY ./target/nr-engine.war $CATALINA_HOME/webapps/nr-engine.war
[2021-11-10 18:54:30] COPY failed: stat /var/lib/docker/tmp/docker-builder408548833/target/nr-engine.war: no such file or directory
script returned exit code 1
把拷贝的源路径改成绝对路径“/nr-engine/target/nr-engine.war”也一样。。。
后来在Dockerfile中加了命令 ls,发现目录确实是存在的;
后来又加命令 ls -l target ,发现没权限!应该是这个原因,才会导致拷贝(ADD 和 COPY 都试过)失败。
有谁碰到过吗?这是什么情况?
以下是Dockerfile:
FROM maven:3.8.3-openjdk-8
# 指定Maven环境变量(这里由于使用官方镜像,路径按照官方镜像Dockerfile中的来,否则会找不到mvn)
ENV MAVEN_HOME /usr/share/maven
ENV PATH $MAVEN_HOME/bin:$PATH
WORKDIR /nr-engine
COPY ./nr-engine/pom.xml .
COPY ./nr-engine/src ./src
COPY ./nr-engine/setting.xml ./setting.xml
RUN rm -rf target && mkdir -m +r "target"
RUN ${MAVEN_HOME}/bin/mvn -U clean package --settings /nr-engine/setting.xml -DskipTests
# 添加tomcat容器到镜像中
FROM tomcat:jre8-openjdk
# 保险起见,按照tomcat官方镜像配置环境变量
ENV CATALINA_HOME /usr/local/tomcat
ENV PATH $CATALINA_HOME/bin:$PATH
# 将war包添加进tomcat
#
# ADD nr-engine.war $CATALINA_HOME/webapps/
COPY ./target/nr-engine.war $CATALINA_HOME/webapps/nr-engine.war
# 指定端口
EXPOSE 8080
# CMD ["catalina.sh", "run"]
RUN $CATALINA_HOME/bin/catalina.sh
环境参数:
环境id:env-joker-6gp22nkt49926152
服务名称:jz
版本:jz-023
状态:构建失败
你好,你那边采用的构建模式属于docker17版本之后的分阶段构建技术,第一阶段构建出来的产物需要as成一个builder,在第二阶段需要把这个builder拷贝到tomcat容器中,这样就可以了,麻烦试试看。
增加 as builder,并且copy时使用--from参数,确实解决了~