【问题标题】:target does not exist when use docker-maven-plugin to build docker image使用docker-maven-plugin构建docker镜像时target不存在
【发布时间】:2020-08-07 20:25:12
【问题描述】:

当我使用 docker-maven-plugin 构建 docker 镜像时,它失败了

错误:无法在项目 spring-boot-basic 上执行目标 com.spotify:docker-maven-plugin:1.0.0:build (default-cli):捕获异常:basedir /root/workSpace/spring-boot-基本/spring-boot-basic-web/target 不存在

这是 pom.xml 的一些代码

<!-- docker plugin -->
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>1.0.0</version>
            <!-- docker config -->
            <configuration>
                <!-- image name -->
                <imageName>${project.build.finalName}</imageName>
                <!-- image tag -->
                <imageTags>
                    <imageTag>${project.version}</imageTag>
                </imageTags>
                <dockerDirectory>${project.basedir}</dockerDirectory>
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.basedir}/${jar.real.path}/target</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
            </configuration>
        </plugin>

这是我的项目结构

spring-boot-basic
Dockerfile
module----spring-boot-basic-web
          src/main--------MainApp.java 
pom.xml              

target 将在 spring-boot-basic-web(module) 中构建

但是当我运行 'mvn clean package' 时,它构建成功并生成目标文件夹

然后我运行 'mvn clean package docker:build' ,它构建 docker 映像成功但错误仍然发生

我该如何解决这个错误?

【问题讨论】:

    标签: spring-boot docker maven


    【解决方案1】:

    现在我知道为什么会导致我在父 pom 中配置 maven docker 插件的问题,其中包类型是“pom”而不是“jar”,所以当我构建项目时会出现问题。 所以我将 maven docker config 放在模块“spring-boot-basic-web”中,然后构建成功。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-06
      • 1970-01-01
      • 2020-10-06
      • 1970-01-01
      • 2018-08-22
      • 1970-01-01
      相关资源
      最近更新 更多