所以我尝试在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专业版。请我需要你的帮助
3条答案
按热度按时间czq61nw11#
可能是Unable to run './mvnw clean install' when building docker image based on "openjdk:8-jdk-alpine" for Spring Boot app的副本
您可以检查
mvnw
shell脚本的行尾吗?您可以通过在执行mvnw
命令之前添加以下内容来修复它:或者,如果文件在git中,你也可以在
.gitattributes
文件中添加以下代码,然后再次 checkout 该文件:wvyml7n52#
你必须先把项目文件复制到
/app
目录中,而且在运行docker build
的上下文文件夹中没有maven Package 器。hmae6n7t3#
尝试将mvnw文件的行尾从Windows风格的CRLF更改为Unix风格的LF。然后重建映像。