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...
According to the Dockerfile specification, if multiple sources are specified, then the destination must be a directory, and it must end with a slash '/'.
The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.
From the official docs of docker for . dockerignore: Before the docker CLI sends the context to the docker daemon, it looks for a file named . dockerignore in the root directory of the context.
In your Dockerfile,
ARG war_FILE=/home/app/target/*.war
COPY ${war_FILE} app.war
Due to some reason, the ${war_FILE}
is not getting updated. Can you check whether .war
files are present at the /home/app/target/
after the build?
Also, if the war_FILE
is a constant, why not directly copying the files from that location? i.e.
COPY /home/app/target/*.war app.war
Again, if there will be multiple .war
files this can be a problem
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With