英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论