0

我想在我的 Docker 映像中包含一些 JAR 文件。我正在使用 fabric8 maven 插件的内联汇编功能。

这是 POM 中的依赖项:

<dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-all</artifactId>
    <version>${activemq.version}</version>
    <type>jar</type>
</dependency>
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>${org.json.version}</version>
    <type>jar</type>
</dependency>

这是 fabribc8 插件的内联程序集:

<assembly>
    <inline>
        <id>copy-jars</id>
        <dependencySets>
            <dependencySet>
                <includes>
                    <include>*</include>
                </includes>
                <outputDirectory>/opt/apache-jmeter-5.1.1/lib</outputDirectory>
            </dependencySet>
        </dependencySets>
    </inline>
</assembly>

JAR 被复制到target/docker/...目录中。截屏:

智能截图

我构建图像,运行容器,然后进入它。但是,缺少 JAR。

bash-4.4# ls -l /opt/apache-jmeter-5.1.1/lib/*active*
ls: /opt/apache-jmeter-5.1.1/lib/*active*: No such file or directory

插件有一个警告: [WARNING] DOCKER> Dockerfile /load-testing/Dockerfile does not contain an ADD or COPY directive to include assembly created at maven. Ignoring assembly.

我必须使用 COPY 将文件复制到 Docker 映像中吗?我不是从插件中免费获得的吗?还是我只是配置错误?

4

1 回答 1

0

我在尝试外部 Dockerfile 时也遇到了这个问题。该程序集仅将其复制到目标文件夹,您仍然需要在 Dockerfile 中使用 COPY 来获取它。所以你是对的,你似乎需要两者。

如果你只需要罐子,你也可以在你的 pom 中使用它

<assemblies>
 <assembly>
  <descriptorRef>artifact-with-dependencies</descriptorRef>
 </assembly>
</assemblies>

但是您仍然需要像这样将它们复制到 Dockerfile 中(如果您未在程序集中提供名称,则 maven 是默认文件夹名称)

COPY maven/ /opt/apache-jmeter-5.1.1/lib/
于 2021-05-28T16:32:37.110 回答