Issue
I'm new to Docker (but not to developing).
I have this Dockerfile:
#
# Build stage
#
FROM maven:3.6.3-jdk-8-slim AS build
COPY src /home/app/src
COPY pom.xml /home/app
RUN mvn -f /home/app/pom.xml clean package
#
# Package stage
#
FROM openjdk:8-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
ARG war_FILE=/home/app/target/*.war
COPY ${war_FILE} app.war
ENTRYPOINT ["java","-jar","/app.war"]
And (so far so good) the build succeeds:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:51 min
[INFO] Finished at: 2020-01-15T08:43:54Z
[INFO] ------------------------------------------------------------------------
but in the end, the docker build fails:
Removing intermediate container 7c66e8b7dbed
---> 74b1c50c84ad
Step 5/10 : FROM openjdk:8-jdk-alpine
---> a3562aa0b991
Step 6/10 : RUN addgroup -S spring && adduser -S spring -G spring
---> Running in ca236cf9a705
Removing intermediate container ca236cf9a705
---> 0c255ef5868f
Step 7/10 : USER spring:spring
---> Running in 8452dcff6a8a
Removing intermediate container 8452dcff6a8a
---> 6265f412699a
Step 8/10 : ARG war_FILE=/home/app/target/*.war
---> Running in 3b54067b2cca
Removing intermediate container 3b54067b2cca
---> c186c4a7e443
Step 9/10 : COPY ${war_FILE} app.war
COPY failed: no source files were specified
I'm probably doing something incredibly stupid but I don't know where to start looking...
Solution
On a multistage build, data of each stage is not shared among stages.
Thus, indeed on build
stage you have successfully created the war file under /home/app/target/
.
However, on second stage this path does not exist, resulting in the reported error.
To solve this, replace second stage with:
FROM openjdk:8-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
COPY --from=build /home/app/target/war_name.war app.war
ENTRYPOINT ["java","-jar","/app.war"]
Example from official docs.
Answered By - leopal
Answer Checked By - Candace Johnson (JavaFixing Volunteer)