【问题标题】:ADD failed: file not found in build context or excluded by .dockerignore:添加失败:在构建上下文中找不到文件或被 .dockerignore 排除:
【发布时间】:2022-06-30 17:26:56
【问题描述】:

这是我的 Dockerfile:

FROM openjdk:8
EXPOSE 8080
ADD target/springboot-example.jar springboot-example.jar
ENTRYPOINT ["java","-jar","/springboot-example.jar"]

在运行docker build 时,我看到了这个错误:

第 3/4 步:添加目标/springboot-example.jar springboot-example.jar
添加失败:在构建上下文中找不到文件或被 .dockerignore 排除:stat target/springboot-example.jar:文件不存在

【问题讨论】:

  • 您确定文件target/springboot-example.jar 存在吗?它可能有不同的名称,具体取决于如何配置 jar 名称生成例如,如果您在 .jar 之前的名称中内置了版本,则可以使用通配符:ADD target/springboot-example*.jar springboot-example.jar
  • 您是否尝试过指定 WORKDIR?

标签: java spring-boot docker docker-image rancher-desktop


【解决方案1】:

在我的情况下,目标文件与 pom.xml 文件不匹配。

您的目标 springboot-example 是 pom.xml 中的 (<artifactId>+<version>.jar)。我认为您在 dockerfile 中声明的 springboot-example 与 pom.xml 文件中的 artifactIdversion 标记不匹配。只需确保您的项目遵循以下步骤:

步骤一

转到 pom.xml 文件并确保您的 <grupId><artifactId> 与您的 Dockerfile 目标相同

第二步

设置 Dockerfile,我的项目是这样的:

FROM openjdk:17
ADD target/intermnc-0.0.1.jar intermnc-0.0.1.jar
EXPOSE 8081
ENTRYPOINT ["sh", "-c", "java ${JAVA_OPTS} -jar intermnc-0.0.1.jar"]

在我的情况下它已经解决了,祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-16
    • 2020-05-15
    • 2021-12-19
    • 2017-08-10
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 2012-08-13
    相关资源
    最近更新 更多