10

Docker对 fabric8io很陌生docker-maven-plugin。我很难将 .war 部署到由该图像派生的图像中jboss/wildfly。我可以通过命令行成功构建 .war 附带的图像,但我不能通过已经提到的插件来做同样的事情。据我所知,一旦你给出正确的上下文,Dockerfile它应该只是一个问题:

<build>
  <finalName>${project.build.finalName}.${project.packaging}</finalName>
  ...
  <assembly>
    <descriptorRef>artifact</descriptorRef>
  </assembly>
</build>

但我遇到了这个错误:

[INFO] <<< docker-maven-plugin:0.19.0:build (default-cli) < package @ YoOffer <<<
[INFO] 
[INFO] --- docker-maven-plugin:0.19.0:build (default-cli) @ YoOffer ---
[WARNING] Cannot include project artifact: edu.pezzati.yo:YoOffer:war:0.0.1-SNAPSHOT; it doesn't have an associated file or directory.
[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  'edu.pezzati.yo:YoOffer'

[ERROR] DOCKER> Failed to create assembly for docker image  (with mode 'dir'): Error creating assembly archive docker: You must set at least one file.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

是我的沙箱。

更新: 我清理了我的 pom 中的一些乱七八糟的东西。现在看起来像这样:

<images>
    <image>
        <alias>yowildfly</alias>
        <name>jboss/wildfly</name>
        <build>
        <!--
            <assembly>
                <descriptorRef>${project.basedir}/src/test/resources/DOCKER/assembly.xml</descriptorRef>
            </assembly>
        -->
            <args>
                <webapp>target/${project.build.finalName}.${project.packaging}</webapp>
            </args>
            <dockerFileDir>${project.basedir}</dockerFileDir>
            <dockerFile>src/test/resources/DOCKER/wildfly/Dockerfile</dockerFile>
            </build>
            <run>
                <ports>
                    <port>8080:8080</port>
                </ports>
            </run>
        </image>
...
</images>

现在我收到此错误:

...    
[ERROR] DOCKER> Unable to build image [jboss/wildfly]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.769 s
[INFO] Finished at: 2017-02-12T01:19:57+01:00
[INFO] Final Memory: 36M/271M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.fabric8:docker-maven-plugin:0.19.0:build (default-cli) on project YoOffer: Unable to build image [jboss/wildfly]: lstat target/YoOffer.war: no such file or directory -> [Help 1]
[ERROR]
...

根据文档,dockerFileDirdockerFile应该标记图像构建上下文一起使用。

4

2 回答 2

2

我误解了 fabric8io docker 插件文档。您可以一起使用dockerFileDirdockerFile但构建上下文不会设置为dockerFileDir值。要部署我的工件,target我必须将我放到项目的根目录,使用项目根路径Dockerfile设置值,从我的. 我的沙箱就是这样更新的。下一步是通过使用in conf 以更简洁的方式实现相同的目的。dockerFileDirdockerFilepomassemblybuild

于 2017-02-13T08:21:28.597 回答
1

由于 Docker 的工作方式,您应该能够将它放在Dockerfile任何您想拥有的地方,而不受任何限制。因此,io.fabric8 maven 插件中有一个选项,允许您在构建 docker 映像期间复制所需的文件。这就是它对我的工作方式:

  1. 我决定把我的Dockerfile放到 src/main/docker
  2. 在 docker 镜像构建期间我需要两个文件:
    • target/SomeName.war(这是包maven阶段的产物)
    • src/main/resources/OtherFiles.xml(这只是我也需要的另一个资源)

文件中的 io.fabric8 插件配置pom.xml

<plugin>
  <groupId>io.fabric8</groupId>
  <artifactId>docker-maven-plugin</artifactId>
  <version>0.24.0</version>
  <configuration>
    <images>
      <image>
        <name>some/name</name>
        <build>
          <dockerFileDir>${project.basedir}/src/main/docker</dockerFileDir>
          <dockerFile>Dockerfile</dockerFile>
          <assembly>
            <mode>dir</mode>
            <name>maven/</name>
            <inline xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
              <id>middleware-rest</id>
              <files>
                <file>
                  <source>${project.build.directory}/SomeName.war</source>
                  <outputDirectory>./</outputDirectory>
                  <destName>SomeName.war</destName>
                </file>
                <file>
                  <source>${project.basedir}/src/test/resources/OtherFiles.xml</source>
                  <outputDirectory>./</outputDirectory>
                  <destName>OtherFiles.xml</destName>
                </file>
              </files>
            </inline>
          </assembly>
        </build>
        <run>
          <ports>
            <port>8080:8080</port>
          </ports>
          <network>
            <mode>host</mode>
          </network>
          <wait>
            <log>.*WildFly .* \(WildFly .*\) started in [0-9]*ms - Started [0-9]* of [0-9]* services</log>
            <time>360000</time>
          </wait>
        </run>
      </image>
    </images>
    <showLogs>true</showLogs>
  </configuration>
  <!-- Connect start/stop to pre- and post-integration-test phase, respectively if you want to start your docker containers during integration tests -->
  <executions>
    <execution>
      <id>start</id>
      <phase>pre-integration-test</phase>
      <goals>
        <!-- "build" should be used to create the images with the artifact -->
        <goal>build</goal>
        <goal>start</goal>
      </goals>
    </execution>
    <execution>
      <id>stop</id>
      <phase>post-integration-test</phase>
      <goals>
        <goal>stop</goal>
      </goals>
    </execution>
  </executions>
</plugin>

最后我如何在以下文件中引用这些文件Dockerfile

ADD maven/SomeName.war /opt/jboss/wildfly/standalone/deployments/

请注意,这maven是您放在pom.xml( <name>maven/</name>) 中的名称。当然,您可以使用任何您想要的东西。

于 2018-07-07T15:47:03.207 回答