Hi everyone,
I’m trying to build a Spring Boot application using Docker, but I keep running into an issue where the target directory can’t be found after running commands in my Dockerfile.
Here’s my Dockerfile:
# Stage 1: Build the application
FROM maven:3.9.4-eclipse-temurin-17 AS build
WORKDIR /app
# Copy the source code to the container
COPY . .
# Use Maven to build the project and skip tests if needed
RUN mvn clean package -DskipTests
# Stage 2: Run the application
FROM --platform=linux/amd64 openjdk:17-jdk-alpine
WORKDIR /app
# Copy the built JAR file from the previous stage
COPY --from=build /app/module-ceone-1.0.0.jar app.jar
# Expose the port that the application will run on
EXPOSE 8080
# Run the application
ENTRYPOINT ["java", "-jar", "app.jar"]
Error:sudo docker build -f Dockerfile.qovery .
[+] Building 48.2s (12/12) FINISHED
=> [internal] load build definition from Dockerfile.qovery 0.0s
=> => transferring dockerfile: 605B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for Docker Hub Container Image Library | App Containerization 0.0s
=> [internal] load metadata for Docker Hub Container Image Library | App Containerization 0.8s
=> [build 1/4] FROM Docker Hub Container Image Library | App Containerization 0.0s
=> [internal] load build context 10.6s
=> => transferring context: 416.99MB 10.6s
=> [stage-1 1/3] FROM Docker Hub Container Image Library | App Containerization 0.0s
=> CACHED [stage-1 2/3] WORKDIR /app 0.0s
=> CACHED [build 2/4] WORKDIR /app 0.0s
=> [build 3/4] COPY . . 1.1s
=> [build 4/4] RUN mvn clean package -DskipTests 35.4s
=> ERROR [stage-1 3/3] COPY --from=build /app/module-ceone-1.0.0.jar app.jar 0.0s
[stage-1 3/3] COPY --from=build /app/module-ceone-1.0.0.jar app.jar:
failed to compute cache key: “/app/module-ceone-1.0.0.jar” not found: not found
The error occurs at the COPY --from=build /app/target/*.jar app.jar
step because the target
directory is not found. I’ve added ls
commands in the Dockerfile for debugging, but it seems like the target
directory never gets created.
I’ve confirmed that the build works locally with mvn clean package -DskipTests
, and the JAR file is generated in target/
. I’m not sure why it’s not working in the Docker build.
Has anyone encountered this issue or knows what could be causing it? Any advice would be greatly appreciated.
Thank you!