Reputation: 3908
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?
Upvotes: 1
Views: 4343
Reputation: 2717
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
Upvotes: 1