Spring Boot - Target Directory Not Found After Running Commands in Dockerfile

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!

Hello @unocat,

Can you share with us the URL link of your console please?

With it, I’ll be able to check your problem.

Regards,
Charles-Edouard

Thank you! I’ve resolved the Dockerfile failure issue. The main problem was with the COPY file path. My Spring project has multiple modules, and the submodule module-project includes its own pom.xml and target directories, so it required more handling compared to a standard Dockerfile setup.

Here is my dockerfile

# Stage 1: Build the application
FROM maven:3.9.4-eclipse-temurin-17 AS build
WORKDIR /app

# Copy the entire project to the container
COPY . .

# Build only the module-ceone module, and skip tests if needed
RUN mvn -f /app/pom.xml clean package -pl module-project -am -DskipTests

# Stage 2: Run the application
FROM openjdk:17-jdk-alpine
WORKDIR /app

# Set environment variables for the application
ENV SPRING_PROFILES_ACTIVE=dev

# Copy the built JAR file from the previous stage
COPY --from=build /app/module-project/target/module-project-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"]

Hello
I have another problem:

“CreateError - Error, cannot get Kubernetes nodegroup list from your cloud provider.”

My console:https://console.qovery.com/organization/f5e8ba8b-c271-4b9a-a2b2-91d8e674b0fb/project/dbc04068-257a-4452-9152-f86ad9cfaf47/environments/general

Hello @unocat ,

I forwarded your problem to the team,
I’ll get back to you with a solution

Regards,
Charles-Edouard

I close this thread,

We’ll continue in the other one.