skip to Main Content

I am building a Docker container using the following Dockerfile and actually the app is running on the created container.

FROM eclipse-temurin:17-jdk-jammy as builder
RUN addgroup demogroup; adduser --ingroup demogroup --disabled-password demo
USER demo
WORKDIR /app

# copy pom.xml, mvnw and source code
COPY .mvn/ .mvn
COPY mvnw ./
COPY pom.xml ./
COPY src/ src

#RUN dos2unix ./mvnw
RUN ./mvnw clean install  <-- this line gives error


# Second stage: minimal runtime environment
FROM eclipse-temurin:17-jre-jammy
WORKDIR /app

# copy jar from the first stage
COPY --from=builder /app/target/*.jar /app/app.jar

EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app/app.jar"]

When executing RUN ./mvnw clean install line, I get " /bin/sh: 1: ./mvnw: not found" error. I tried many things, but cannot fix it. Is there any problem in my Dockerfile?

2

Answers


  1. RUN mvn 
    

    runs mvn inside the docker image.

    The docker image is basically a pared down Linux image. Or a Windows image, or whichever OS was used as the base image.

    Presuming your base image is Linux, after docker build completed, at your project folder, you can do
    docker run -it

    and you will be in your dockerized Linux image, where you can run basic Linux commands (provided your image has those basic commands installed).

    You can then navigate and inspect if your docker image.

    Login or Signup to reply.
  2. To solve the problem, include Maven build in your Dockerfile instead of running maven command from project folder via mvnv:

    COPY src/main/resources/data/ ./src/data
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search