使用spotify / dockerfile-maven-plugin推送docker hub时出错

时间:2017-12-12 16:13:16

标签: java maven docker dockerhub maven-docker-plugin

我有一个maven项目,它是作为docker镜像构建的。我使用spotify/dockerfile-maven构建此图片并自动将其推送到mvn clean install上的docker.hub。 build阶段没有任何问题。但在push我有这个错误:

[ERROR] denied: requested access to the resource is denied
[WARNING] An attempt failed, will retry 1 more times
org.apache.maven.plugin.MojoExecutionException: Could not push image
    at com.spotify.plugin.dockerfile.PushMojo.execute(PushMojo.java:90)
........
Caused by: com.spotify.docker.client.exceptions.DockerException: denied: requested access to the resource is denied
    at com.spotify.plugin.dockerfile.LoggingProgressHandler.handleError(LoggingProgressHandler.java:105)
    at com.spotify.plugin.dockerfile.LoggingProgressHandler.progress(LoggingProgressHandler.java:63)
......

这是我的插件配置:

     <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.spotify</groupId>
                    <artifactId>dockerfile-maven-plugin</artifactId>
                    <version>1.3.6</version>
                    <configuration>
                        <repository>${docker.image.prefix}/${project.artifactId}-istio</repository>
                        <tag>latest</tag>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>build</goal>
                                <goal>push</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

使用docker push image-name:tag推送时,一切正常。

Here我发现了类似的问题,但添加docker-client v8.8.4的依赖关系不会改变任何内容。

另外,this评论建议切换到1.3.3版本,但这对我不起作用。

对于这两种情况,我可以在日志中看到它推送到同一个存储库:

The push refers to a repository [docker.io/my-login/my-image-name]

3 个答案:

答案 0 :(得分:1)

您是否在~/.m2/settings.xml文件中创建了serverId?
喜欢这里:

<servers>
  <server>
    <id>docker-hub</id>
    <username>your_docker_hub_username</username>
    <password>you_docker_hub_password</password>
    <configuration>
      <email>your_docker_hub_email@example.com</email>
    </configuration>
  </server>
</servers>

然后,您需要在pom.xml(serverId)中引用它。

    <build>
    <plugins>
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>1.0.0</version>
            <configuration>
            <!--related to creating image and pushing it to docker hub-->
                <imageName>${docker.image.prefix}/${project.artifactId}-istio</imageName>
                <imageTags>
                    <imageTag>latest</imageTag>
                </imageTags>
                <serverId>docker-hub</serverId>
                <registryUrl>https://index.docker.io/v1/</registryUrl>
            <!--end of related to creating image and pushing it to docker hub-->
            </configuration>
        </plugin>

可以找到有关身份验证的文档here
我使用mvn clean install docker:build来构建图片,但我猜您使用<executions>...</executions>的方法也应该有效 使用建议的mvn命令给我提供的配置(和docker-maven-plugin版本),并告诉我这是否有帮助。

答案 1 :(得分:1)

<useMavenSettingsForAuth>true</useMavenSettingsForAuth>添加到配置标签,并在maven settings.xml中将服务器凭据指定为-

<server>
      <id>docker.io</id>
      <username>xxxxx</username>
      <password>xxxxxx</password>
    </server>

答案 2 :(得分:-1)

我假设您没有收到说找不到 docker.io 服务器引用的错误,这意味着您的 settings.xml 凭据选择正确。可能是 ${docker.image.prefix} 不是正确的 hub.docker.com 用户名。尝试对其进行硬编码,看看它是否有效。