0

我正在尝试将 maven dockerfile 插件与我的项目集成。我的 Maven 项目下有多个模块。我已经为要构建的模块修改了pom.xml并标记图像,如下所示。运行mvn dockerfile:build命令 build adocker-info.jar在目标文件夹下创建一个。我不确定图像是在哪里构建的,当我尝试运行mvn dockerfile:tag命令时,我看到以下错误。

无法在项目 drs-web 上执行目标 com.spotify:dockerfile-maven-plugin:1.4.4:tag (default-cli):目标 com.spotify:dockerfile-maven-plugin:1.4.4 的参数“存储库” :tag 丢失或无效

Pom.xml:

    <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <version>${docker.maven.plugin.version}</version>
                    <executions>
                        <execution>
                            <id>build</id>
                            <goals>
                                <goal>build</goal>
                            </goals>
                            <configuration>
                                <buildArgs>
                                    <WAR_FILE>${project.build.finalName}.war</WAR_FILE>
                                </buildArgs>
                            </configuration>
                        </execution>
                        <execution>
                            <id>tag</id>
                            <goals>
                                <goal>tag</goal>
                            </goals>
                            <configuration>
                                <repository>XXX/XXX-api</repository>
                                <tag>${project.version}</tag>
                            </configuration>
                        </execution>
                    </executions>
            </plugin>

Dockerfile:

FROM tomcat:9.0.10-jre8-slim
ENV CATALINA_HOME /usr/local/tomcat
MAINTAINER XXX
EXPOSE 8080
ADD target/${WAR_FILE} ${CATALINA_HOME}/webapps/XXX-api.war
4

1 回答 1

2

要修复错误,您应该在 pom.xml 的两个部分中使用相同的参数。您没有为构建目标定义存储库的名称:

<configuration>
    <repository>XXX/XXX-api</repository>
</configuration>

在 Target 目录中创建docker-info.jar的事实很可能意味着 docker 映像的创建已成功完成。

该图像应该以“XXX/XXX-api”的名称放入您的 Docker 注册表,您可以使用以下命令从控制台检查它:

docker image ls

PS您可以通过在dockerfile-maven-plugin的配置部分添加以下参数来避免生成docker- info.jar:

<configuration>
    <skipDockerInfo>true</skipDockerInfo>
</configuration>
于 2019-04-01T17:47:07.380 回答