简体   繁体   English

Dockerfile: /bin/sh: 1: ./mvnw: 找不到错误

[英]Dockerfile : /bin/sh: 1: ./mvnw: not found error

I am building a Docker container using the following Dockerfile and actually the app is running on the created container.我正在使用以下Dockerfile构建一个 Docker 容器,实际上该应用程序正在创建的容器上运行。

FROM eclipse-temurin:17-jdk-jammy as builder
RUN addgroup demogroup; adduser --ingroup demogroup --disabled-password demo
USER demo
WORKDIR /app

# copy pom.xml, mvnw and source code
COPY .mvn/ .mvn
COPY mvnw ./
COPY pom.xml ./
COPY src/ src

#RUN dos2unix ./mvnw
RUN ./mvnw clean install  <-- this line gives error


# Second stage: minimal runtime environment
FROM eclipse-temurin:17-jre-jammy
WORKDIR /app

# copy jar from the first stage
COPY --from=builder /app/target/*.jar /app/app.jar

EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app/app.jar"]

When executing RUN./mvnw clean install line, I get " /bin/sh: 1: ./mvnw: not found" error.执行RUN./mvnw clean install行时,出现“/bin/sh: 1: ./mvnw: not found”错误。 I tried many things, but cannot fix it.我尝试了很多东西,但无法修复它。 Is there any problem in my Dockerfile?我的Dockerfile有问题吗?

RUN mvn 

runs mvn inside the docker image.在 docker 图像中运行 mvn。

The docker image is basically a pared down Linux image. docker 图像基本上是 Linux 图像的缩减版。 Or a Windows image, or whichever OS was used as the base image.或 Windows 图像,或用作基础图像的任何操作系统。

Presuming your base image is Linux, after docker build completed, at your project folder, you can do docker run -it假设您的基本映像是 Linux,在 docker 构建完成后,您可以在您的项目文件夹中执行 docker run -it

and you will be in your dockerized Linux image, where you can run basic Linux commands (provided your image has those basic commands installed).并且您将位于 dockerized Linux 图像中,您可以在其中运行基本的 Linux 命令(前提是您的图像安装了这些基本命令)。

You can then navigate and inspect if your docker image.然后您可以导航并检查您的 docker 图像。

To solve the problem, include Maven build in your Dockerfile instead of running maven command from project folder via mvnv :要解决此问题,请在Dockerfile中包含Maven build ,而不是通过mvnv从项目文件夹运行 maven 命令:

COPY src/main/resources/data/ ./src/data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM