Spotify dockerfile could't push image, resource is deined

720 views Asked by At

I am using Spotify Dockerfile maven plugin like this

<plugins>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <version>1.4.10</version>
                <executions>
                    <execution>
                        <id>default</id>
                        <goals>
                            <goal>build</goal>
                            <goal>push</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <username>myUserName</username>
                    <password>myPassword</password>
                    <repository>dockerhubUsername/dockerhubRepo</repository>
                    <tag>latest</tag>
                    <buildArgs>
                        <JAR_FILE>${project.artifactId}.jar</JAR_FILE>
                    </buildArgs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>

So whenever I build using mvn deploy I get this error

[ERROR] Failed to execute goal com.spotify:dockerfile-maven-plugin:1.4.10:push (default) on project nepse-sim: Could not push image: denied: requested access to the resource is denied -> [Help 1]

I have specified my dockerhub username and password there in the configuration but still I am getting this error. Any help would be appreciated. Thanks

1

There are 1 answers

0
rahul sharma On

First of all, Do not put your credentials in pom.xml because this will be in git or whatever you are using. So add your credentials in settings.xml inside .m2 folder.

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

Change your configuration tag in pom.xml as below -

<configuration>
    <repository>dockerhubUsername/dockerhubRepo</repository>
    <tag>${project.version}</tag>
    <useMavenSettingsForAuth>true</useMavenSettingsForAuth>
    <buildArgs>
        <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
    </buildArgs>
</configuration>

Then It should work.