我对Docker和fabric8io docker-maven-plugin非常陌生。要将.war部署到jboss/wildfly one导出的映像中,我遇到了一些困难。我可以通过命令行成功地构建.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]
...因此,对于docs,与dockerFile一起使用的dockerFile应该标记映像构建上下文。
发布于 2017-02-13 08:21:28
我误解了fabric8io的插件文档。您可以同时使用dockerFileDir和dockerFile,但是构建上下文不会被设置为dockerFileDir值。要从target部署我的工件,我必须将Dockerfile放到我的项目的根目录,用项目根路径设置dockerFileDir值,从Dockerfile中删除dockerFile条目。我的沙盒是这样更新的。下一步是通过在assembly中使用build conf,以一种更干净的方式实现同样的目标。
发布于 2018-07-07 15:47:03
您应该能够将您的Dockerfile放在您想要的任何位置,而不受Docker工作方式的限制。因此,在io.fabric8 maven插件中有一个选项,它允许您复制您在构建码头映像时所需的文件。对我来说是这样的:
Dockerfile放进src/main/dockertarget/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>)中输入的名称。你当然可以用你想要的任何东西来代替。
https://stackoverflow.com/questions/42095214
复制相似问题