Spotify dockerfile-maven-plugin如何使用"docker-compose build"? [英] How's spotify dockerfile-maven-plugin uses "docker-compose build"?

查看:917
本文介绍了Spotify dockerfile-maven-plugin如何使用"docker-compose build"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从文档 https://github.com/spotify/dockerfile-maven 中,它说:

例如,一个docker-compose.yml可能看起来像:

For example, a docker-compose.yml might look like:

 service-a:
   build: a/
   ports:
   - '80'

 service-b:
   build: b/
   links:
   - service-a

现在,docker-compose up和docker-compose构建将按预期工作.

Now, docker-compose up and docker-compose build will work as expected.

但是如何编写pom.xml文件,仍然好像不使用compose一样?将目标设置为构建"?

But how to write the pom.xml file, still like as if not using compose? Set the goal to be "build"?

<plugin>
  <groupId>com.spotify</groupId>
  <artifactId>dockerfile-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>default</id>
      <goals>
        <goal>build</goal>
      </goals>
    </execution>
  </executions>
</plugin>

推荐答案

您无法使用spotify插件从docker-compose.yml文件开始构建映像.自述文件提到设计目标是:

You cannot build the images starting from a docker-compose.yml file using the spotify plugin. The readme mentions that the design goal was:

别做任何幻想. Dockerfiles是您构建Docker的方式 项目;这就是该插件的用途.

Don't do anything fancy. Dockerfiles are how you build Docker projects; that's what this plugin uses.

您引用的那一部分文档实际上说,在Maven多模块项目结构上,可以轻松使用其他构建工具,例如docker-compose.

That section of the docs you quoted actually says that on a maven multi-module project structure one can easily use other build tools such as docker-compose.

尽管如此,仍有一些方法可以从docker-compose.yml中使用Maven进行构建.一种是与 maven-exec

Nevertheless, there are ways to build with maven from a docker-compose.yml. One is with the maven-exec

有关文件:

version: "2"
services:
  service-a:
    build: a/
    image: imga

  service-b:
    build: b/
    image: imgb
    links:
      - service-a

pom.xml的相关部分将类似于以下内容:

the relevant part of the pom.xml would be something like the following:

<build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
          <execution>
            <id>docker-build</id>
            <phase>package</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>docker-compose</executable>
              <workingDirectory>${project.basedir}</workingDirectory>
              <arguments>
                <argument>build</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

另一种解决方案是使用 fabric8

Another solution is to use fabric8

<build>
    <plugins>
      <plugin>
        <groupId>io.fabric8</groupId>
        <artifactId>docker-maven-plugin</artifactId>
        <version>0.26.0</version>
        <executions>
          <execution>
            <id>docker-build</id>
            <phase>package</phase>
            <goals>
              <goal>build</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <images>
            <image>
              <external>
                <type>compose</type>
                <basedir>${project.basedir}</basedir>
                <composeFile>docker-compose.yml</composeFile>
              </external>
            </image>
          </images>
        </configuration>
      </plugin>
    </plugins>
  </build>

使用最适合您的一种.

Use the one that suits you best.

这篇关于Spotify dockerfile-maven-plugin如何使用"docker-compose build"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆