I’m trying to build a Docker image for a Java application using Maven, but I’m encountering an error during the Docker build process. Here’s my Dockerfile:
<code># Build stage
FROM eclipse-temurin:21 AS build
WORKDIR /app
#COPY pom.xml .
#COPY src ./src
#RUN mvn clean package -DskipTests
# Runtime stage
FROM eclipse-temurin:21
WORKDIR /app
COPY --from=build /app/target/uprightcleaningservices-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
</code>
<code># Build stage
FROM eclipse-temurin:21 AS build
WORKDIR /app
#COPY pom.xml .
#COPY src ./src
#RUN mvn clean package -DskipTests
# Runtime stage
FROM eclipse-temurin:21
WORKDIR /app
COPY --from=build /app/target/uprightcleaningservices-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
</code>
# Build stage
FROM eclipse-temurin:21 AS build
WORKDIR /app
#COPY pom.xml .
#COPY src ./src
#RUN mvn clean package -DskipTests
# Runtime stage
FROM eclipse-temurin:21
WORKDIR /app
COPY --from=build /app/target/uprightcleaningservices-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
When I try to build the Docker image, I get the following error:
ERROR: failed to solve: process “/bin/sh -c mvn clean package -DskipTests” did not complete successfully: exit code: 127
- The mvn clean package -DskipTests command is supposed to compile and package my Maven project.
- I am using the eclipse-temurin:21 image as the base for both the build and runtime stages.
- The build stage seems to fail because it cannot find the mvn command.
This I have tried
- Verified that the target directory is correctly specified and that Maven builds the project successfully on my local machine.
- Checked the Dockerfile for correct paths and commands.
- Tried using a different base image, but the issue persists.
I expect the docker image to run successfully so I can deploy the application to render