maven 从“openjdk:8-jdk-alpine”为Sping Boot 应用程序构建Docker映像时,无法运行“RUN ./mvnw dependency:go-offline -B”

cnjp1d6j  于 2022-12-17  发布在  Maven
关注(0)|答案(3)|浏览(331)

所以我尝试在Docker容器中运行一个带有Maven Package 器的Sping Boot 应用程序。以下是我的Docker文件:

### 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)

我有这个错误:

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

我正在使用windows 10专业版。请我需要你的帮助

czq61nw1

czq61nw11#

可能是Unable to run './mvnw clean install' when building docker image based on "openjdk:8-jdk-alpine" for Spring Boot app的副本
您可以检查mvnw shell脚本的行尾吗?您可以通过在执行mvnw命令之前添加以下内容来修复它:

RUN dos2unix mvnw

或者,如果文件在git中,你也可以在.gitattributes文件中添加以下代码,然后再次 checkout 该文件:

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

wvyml7n52#

你必须先把项目文件复制到/app目录中,而且在运行docker build的上下文文件夹中没有maven Package 器。

hmae6n7t

hmae6n7t3#

尝试将mvnw文件的行尾从Windows风格的CRLF更改为Unix风格的LF。然后重建映像。

相关问题