Docker 无法找到生成的 JAR 文件。

huangapple go评论151阅读模式
英文:

Docker can't find generated jar file

问题

I can't figure out why Docker can't find the created jar file in the following Dockerfile:

FROM maven:latest

ENV APP_HOME=/app/

COPY pom.xml $APP_HOME
COPY src $APP_HOME/src/
WORKDIR $APP_HOME

RUN mvn package -DskipTests
ENV JAR_FILE=target/spring-boot-app-0.0.1-SNAPSHOT.jar

COPY ${JAR_FILE} /app.jar

EXPOSE 8300
ENTRYPOINT ["java", "-jar", "/app.jar"]

when building the image with: docker build -t spring-boot-app ., it fails with:

Step 9/11 : COPY ${JAR_FILE} /app.jar
COPY failed: stat /var/lib/docker/tmp/docker-builder834657272/target/spring-boot-app-0.0.1-SNAPSHOT.jar: no such file or directory

If I run mvn clean package before building the image, it works. If I remove the target folder with rm -rf target and rebuild the image, it fails.

What am I missing?

英文:

I can't figure out why Docker can't find the created jar file in the following Dockerfile:

FROM maven:latest

ENV APP_HOME=/app/

COPY pom.xml $APP_HOME
COPY src $APP_HOME/src/
WORKDIR $APP_HOME

RUN mvn package -DskipTests
ENV JAR_FILE=target/spring-boot-app-0.0.1-SNAPSHOT.jar

COPY ${JAR_FILE} /app.jar

EXPOSE 8300
ENTRYPOINT ["java", "-jar", "/app.jar"]

when building the image with: docker build -t spring-boot-app ., it fails with:

Step 9/11 : COPY ${JAR_FILE} /app.jar
COPY failed: stat /var/lib/docker/tmp/docker-builder834657272/target/spring-boot-app-0.0.1-SNAPSHOT.jar: no such file or directory

If I run mvn clean package before building the image, it works. If remove target folder as rm -rf target and rebuild the image, it fails.

What am I missing?

答案1

得分: 1

你正在尝试复制本地构建的jar文件到镜像中,但很可能你只是想将构建的jar文件移到镜像内的另一个路径?

只需将 COPY ${JAR_FILE} /app.jar 替换为 RUN mv ${JAR_FILE} /app.jar

英文:

You're trying to copy your locally built jar file to the image, but most probably you just want to move the jar file you build inside the image to another path?

Just replace the COPY ${JAR_FILE} /app.jar with RUN mv ${JAR_FILE} /app.jar

huangapple
  • 本文由 发表于 2020年8月10日 23:13:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/63342975.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定