Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build docker error /bin/sh: 1: ./mvnw: not found

Tags:

docker

maven

I try to build maven project using dockerfile, but i got this error when i use command docker build

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

i had try this solution : Unable to run './mvnw clean install' when building docker image based on "openjdk:8-jdk-alpine" for Spring Boot app

but still got error.

Here is my dockerfile

# Stage 1 Build the Spring Project into a jar file
FROM openjdk:8-slim as builder
RUN mkdir src
COPY . /src
WORKDIR /src
RUN chmod 700 mvnw && ./mvnw clean install package  ==>error on this line

# Stage 2 Run the jar file from previous build
FROM openjdk:8-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
COPY --from=builder /src/target /build
WORKDIR /build
EXPOSE 80
EXPOSE 5001
ENTRYPOINT ["java", "-jar", "tax-0.0.1-SNAPSHOT.jar"]

Am i missing something? I would be glad for any help.

like image 913
Hans Avatar asked Apr 15 '20 10:04

Hans


1 Answers

I was facing the same issue when building an image based on openjdk:14-alpine from a Windows 10 machine. The issue was that locally the mvnw script had Windows line endings (\r\n called CRLF).

I've tried calling the script with /bin/sh mvnw but I would still have problems. The first solution was to convert the line endings to Linux EOL (\n called "LF") from my IDE.

A better approach is to install dos2unix and run dos2unix mvnw just before calling the script. On Linux Slim (Debian) you may do apt-get update && apt-get install dos2unix.

You may also try chmod +x mvnw to make the script executable.

like image 156
Uyric Avatar answered Sep 28 '22 21:09

Uyric