mavendockerfabric8-maven-plugin

Unable to push docker image with fabric8 plugin


I'm unable to push a docker image to a private repository (hosted on https://hub.docker.com) with fabric8 plugin. I created on hub.docker a repository called: manuzid/heap-dump-sample. It's a simple Spring Boot app only with a loop in the main function. the interesting part is the following in the pom.xml:

<plugin>
            <groupId>io.fabric8</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.27.2</version>
            <configuration>
                <registry>index.docker.io/v1</registry>
                <!-- I think it's not necessary, plugin use the creds from docker config.json -->
                <authConfig>
                    <username>user</username>
                    <password>pw</password>
                </authConfig>
                <images>
                    <image>
                        <name>manuzid/heap-dump-sample:%l</name>
                        <alias>${project.artifactId}</alias>
                        <build>
                            <from>greyfoxit/alpine-openjdk8</from>
                            <entryPoint>
                                <exec>
                                    <arg>java</arg>
                                    <arg>-jar</arg>
                                    <arg>/opt/application/${project.artifactId}-${project.version}.jar</arg>
                                    <arg>-XX:+HeapDumpOnOutOfMemoryError</arg>
                                    <arg>-XX:HeapDumpPath=/dumps/oom.hprof</arg>
                                </exec>
                            </entryPoint>
                            <tags>
                                <tag>${project.version}</tag>
                            </tags>
                            <assembly>
                                <targetDir>/opt/application</targetDir>
                                <descriptorRef>artifact</descriptorRef>
                            </assembly>
                            <env>
                                <AB_ENABLED>jmx_exporter</AB_ENABLED>
                            </env>
                        </build>
                        <run>
                            <wait>
                                <log>Started HeapDumpSampleApplication</log>
                                <time>10000</time>
                            </wait>
                            <env>
                                <JAVA_OPTIONS>-Xmx64m</JAVA_OPTIONS>
                            </env>
                            <log>
                                <file>${project.build.directory}/heap-dump-sample.log</file>
                            </log>
                        </run>
                    </image>
                </images>
            </configuration>
            <executions>
                <execution>
                    <id>docker-build</id>
                    <phase>package</phase>
                    <goals>
                        <goal>build</goal>
                    </goals>
                    <configuration>
                        <filter>${project.artifactId}</filter>
                    </configuration>
                </execution>
                <execution>
                    <id>docker-push</id>
                    <phase>install</phase>
                    <goals>
                        <goal>push</goal>
                    </goals>
                    <configuration>
                        <filter>${project.artifactId}</filter>
                    </configuration>
                </execution>
            </executions>
        </plugin>

I get the following error in the console: [ERROR] DOCKER> Unable to push 'manuzid/heap-dump-sample:latest' from registry 'index.docker.io/v1' : denied: requested access to the resource is denied [denied: requested access to the resource is denied ]

But the specified credentials are the same I use to log into the website (https://hub.docker.com). The specified registry url index.docker.io/v1 is obtained with the command docker info.

Any suggestions on this? Thanks in advance.

Edit: This example can be found here: https://github.com/ManuZiD/heap-dump-sample


Solution

  • I have had issues with both pulling and pushing images and through research which I cannot fully remember I was able to resolve this issue by modifying my Docker credentials store

    Note executing docker login will create this file and also overwrite its contents (I suggest making a backup!)

    The content of config.json should be something like:

    {
        "HttpHeaders": {
            "User-Agent": "Docker-Client/19.03.12 (windows)"
        },
        "auths": {
            "https://hub.docker.com/v1/": {
                "auth": "AUTH-TOKEN"
            },
            "https://index.docker.io/v1/": {
                "auth": "AUTH-TOKEN"
            }
        },
        "credsStore": "desktop",
        "stackOrchestrator": "swarm"
    }
    

    AUTH-TOKEN needs to contain base64{docker-user-id:docker-password}:

    echo "docker-user-id:docker-password" | base64
    

    Note this can be decoded using

    echo AUTH-TOKEN | base64 -d
    

    Warning Never share the contents of your config.json file!

    This is my windows client credentials as you will notice from the user-agent details. OSX users may prefer to utlise an OSX key-chain