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

Viewed 2559

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

2 Answers

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.

Related