无法使用maven插件在docker hub上推送图像

时间:2018-04-17 10:25:23

标签: maven docker fabric8 docker-maven-plugin

我正在使用io.fabric8 docker-maven-plugin来构建并将docker镜像推送到注册表hub.docker.com。图像需要推送到组织下的存储库(例如 xyz )(例如演示)。这是我pom.xml的插件。

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>0.20.1</version>
    <configuration>
        <images>
            <image>
                <name>demo/xyz:${tag}</name>
                <build>
                    <dockerFileDir>${project.basedir}/docker</dockerFileDir>
                </build>
            </image>
         </images>
     </configuration>
     <executions>
         <execution>
             <id>docker-image-build</id>
             <phase>pre-integration-test</phase>
             <goals>
                 <goal>build</goal>
             </goals>
         </execution>
         <execution>
             <id>docker-image-push</id>
             <phase>post-integration-test</phase>
             <goals>
                 <goal>push</goal>
             </goals>
         </execution>
     </executions>
 </plugin>

要推送回购,您的用户名应该在组织中注册。现在,docker镜像构建部分工作正常,但我无法通过docker:push选项推送图像。我阅读并尝试了其他可用的解决方案,例如使用

 <authConfig>
     <username></username>
     <password></password>
 </authConfig>

并在.docker/.config文件中添加了注册表名称,但它没有奏效。我还添加了注册表,但它也没有工作。

<registry>https://hub.docker.com</registry>

推送正在使用

  

docker push

但它没有使用插件。请帮我。感谢。

1 个答案:

答案 0 :(得分:1)

我们正在使用com.spotify docker-maven-plugin我认为它们并没有太大不同 以下是我们pom.xml

的示例
<plugins>
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.4.3</version>
            <configuration>
                <imageName>MY_REGISTRY:443/${project.artifactId}</imageName>
                <imageTags>
                    <imageTag>latest</imageTag>
                </imageTags>
                <dockerDirectory>docker</dockerDirectory>
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.build.directory}</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
                <serverId>MY-REGISTRY</serverId>
                <registryUrl>https://MY_REGISTRY:443/v2/</registryUrl>
            </configuration>
            <executions>
                <execution>
                    <id>docker-build</id>
                    <phase>install</phase>
                    <goals>
                        <goal>build</goal>
                    </goals>
                </execution>

注册表的用户名和密码在settings.xml中设置 以下是我们settings.xml

的示例
<server>
        <id>MY-REGISTRY</id>
        <username>my-user</username>
        <password>my-password</password>
        <configuration>
            <email>developer@my-company.com</email>
        </configuration>
    </server>

我希望这可以帮助您为项目获得正确的配置。

相关问题