简体   繁体   中英

Dockerfile : /bin/sh: 1: ./mvnw: not found error

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM