gpt4 book ai didi

java - 从 'RUN ./mvnw dependency:go-offline -B' 为 Spring Boot 应用程序构建 docker 镜像时,无法运行 "openjdk:8-jdk-alpine"

转载 作者:行者123 更新时间:2023-12-01 17:41:00 27 4
gpt4 key购买 nike

所以我尝试在 docker 容器内运行带有 Maven 包装器的 Spring 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 专业版。请我需要你的帮助

最佳答案

可能是 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

关于java - 从 'RUN ./mvnw dependency:go-offline -B' 为 Spring Boot 应用程序构建 docker 镜像时,无法运行 "openjdk:8-jdk-alpine",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60948766/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com