简体   繁体   中英

Unable to run 'RUN ./mvnw dependency:go-offline -B' when building docker image from "openjdk:8-jdk-alpine" for Spring Boot app

So I am trying to run a spring boot app with maven wrapper inside the docker container. Here is my Docker file:

### Stage 1: Build the application
FROM openjdk:8-jdk-alpine as build

RUN mkdir -p /app
#Set the current working directory inside the image
WORKDIR /app

#copy maven executable to the image
COPY mvnw .
COPY .mvn .mvn

#Copy the pom.xml file
COPY pom.xml .

#Build all the dependencies in preparation to go offline
#This is a separate step so the dependencies will be cached unless
#the pom.xml file has changed

RUN ./mvnw dependency:go-offline -B

#Copy the project source
COPY src src

#Package the application
RUN ./mvnw package -DskipTests
RUN mkdir -p target/dependency && (cd target/dependency; jar -xf ../*.jar)

I have this error:

Step 7/16 : RUN ./mvnw dependency:go-offline -B
 ---> Running in 642a32f86392
/bin/sh: ./mvnw: not found
ERROR: Service 'app-server' failed to build: The command '/bin/sh -c ./mvnw dependency:go-offline -B' returned a non-zero code: 127

I am working with windows 10 pro. Please I need your help

Maybe a duplicate of Unable to run './mvnw clean install' when building docker image based on "openjdk:8-jdk-alpine" for Spring Boot app

Can you check the line endings of the mvnw shell script? You could fix it by adding this before executing the mvnw command:

RUN dos2unix mvnw

Alternatively, if the file is in git, you can also fix it by adding the following to a .gitattributes file and checking the file out again:

*.bat           text eol=crlf
mvnw            text eol=lf

You have to copy the project files into the /app dir first. And you don't have the maven wrapper in the context folder where you run the docker build .

Try change the end of line mvnw file from Windows style CRLF to Unix style LF. Then rebuild the image.

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