Error pushing docker hub using spotify/dockerfile-maven-plugin

4.6k views Asked by At

I have a maven project that is built as a docker image. I'm using spotify/dockerfile-maven to build this image and push it to docker.hub automatically on on mvn clean install. The build phase passes without any problems. But on push I have this error:

[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)
......

Here is my plugin config:

     <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>

When pushing with docker push image-name:tag everything works.

Here I have found the similar issue, but adding the dependency for docker-client v8.8.4 does not change anything.

Also, this comment suggest switching to 1.3.3 version, but this doesn't work for me.

For both cases, I can see in the logs that it pushes to the same repository:

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

There are 2 answers

0
rahul sharma On

Add <useMavenSettingsForAuth>true</useMavenSettingsForAuth> to the configuration tag and specify your server credentials in maven settings.xml as -

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

I assume that you not getting an error that says that docker.io server reference is not found, which means your settings.xml credentials are picked ok. It could be that ${docker.image.prefix} is not correct hub.docker.com username. Try to hardcode it and see if it works.