我尝试使用 dockerfile 构建 maven 项目,但是当我使用命令时出现此错误 docker build
/bin/sh: 1: ./mvnw: not found
我试过这个解决方案:
Unable to run './mvnw clean install' when building docker image based on "openjdk:8-jdk-alpine" for Spring Boot app
但仍然有错误。
这是我的 dockerfile
# Stage 1 Build the Spring Project into a jar file
FROM openjdk:8-slim as builder
RUN mkdir src
COPY . /src
WORKDIR /src
RUN chmod 700 mvnw && ./mvnw clean install package ==>error on this line
# Stage 2 Run the jar file from previous build
FROM openjdk:8-jdk-alpine
RUN addgroup -S spring && adduser -S spring -G spring
USER spring:spring
COPY --from=builder /src/target /build
WORKDIR /build
EXPOSE 80
EXPOSE 5001
ENTRYPOINT ["java", "-jar", "tax-0.0.1-SNAPSHOT.jar"]
我错过了什么吗?
我很乐意提供任何帮助。
最佳答案
在 Windows 10 机器上构建基于 openjdk:14-alpine 的图像时,我遇到了同样的问题。问题是本地 mvnw
脚本有 Windows 行结尾( \r\n
称为 CRLF)。
我试过用 /bin/sh mvnw
调用脚本但我还是会有问题。第一个解决方案是将行尾从我的 IDE 转换为 Linux EOL(\n
称为“LF”)。
更好的方法是安装 dos2unix
并运行 dos2unix mvnw
就在调用脚本之前。在 Linux Slim (Debian) 上你可以做 apt-get update && apt-get install dos2unix
.
您也可以试试 chmod +x mvnw
使脚本可执行。
关于docker - 构建 docker 错误/bin/sh : 1: ./mvnw: not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61226664/