如何使用 Jib 为多模块 Spring Boot 应用构建 Docker 镜像

huangapple 未分类评论41阅读模式
英文:

How to build docker image for multi-module spring boot application using Jib

问题

我有一个 Spring Boot 应用程序,其中有许多模块,例如 error 模块、持久化模块、控制器模块等,如下所示:

    --Application
      |
      -- error 模块
      |
      -- 控制器模块
      |
      -- 持久化模块
      |
      -- .....

使用以下在 pom.xml 中的配置使用 Maven jib 插件来构建此应用程序的 Docker 镜像

                    com.google.cloud.tools
            jib-maven-plugin
            2.4.0
           
             
                some.repo.io/my_name/jib-test
             

             
                com.a.b.c.Application
                                  8080                              

           

       

构建成功。但是当我运行该镜像时,抛出错误 Error: Could not find or load the main class com.a.b.c.Application.

我应该如何使用 Jib 构建镜像?我在这里漏掉了什么?

英文:

I have a Spring boot application which has many modules like error module, persistency, controllers etc like below

--Application
  |
  -- error module
  |
  -- controllers module
  |
  -- Persistancy module
  |
  -- .....

To build docker image for this using Maven jib plugin with below configuration in pom.xml

    <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <version>2.4.0</version>
        <configuration>
          <to>
            <image>some.repo.io/my_name/jib-test</image>
          </to>
          <container>
            <mainClass>com.a.b.c.Application</mainClass>
            <ports>
              <port>8080</port>
            </ports>
          </container>
        </configuration>
    </plugin>

Build is successful. But when I run the image, its throwing error Error: Could not find or load the main class com.a.b.c.Application.

How can I build the image using Jib ?. What am I missing here?

答案1

得分: 0

在您的 pom.xml 文件中添加:

<modules>
    <module>error</module>
    <module>controllers </module>
    <module>Persistancy </module>
</modules>

然后从您的终端运行以下命令:

mvn -Pprod verify com.google.cloud.tools:jib-maven-plugin:dockerBuild
英文:

In your pom.xml, add:

<modules>
    <module>error</module>
    <module>controllers </module>
    <module>Persistancy </module>
</modules>

Then run the following from your terminal:

mvn -Pprod verify com.google.cloud.tools:jib-maven-plugin:dockerBuild

huangapple
  • 本文由 发表于 2020年7月24日 22:22:54
  • 转载请务必保留本文链接:https://java.coder-hub.com/63075571.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定