简体   繁体   中英

Unable to push image on docker hub using maven plugin

I am using io.fabric8 docker-maven-plugin for building and pushing docker image to a registry hub.docker.com . The image needs to be pushed on a repository (For eg. xyz ) which lies under an organization (For eg. demo ). This is my plugin from 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>

To push to the repo, your username should be registered with the organization. Now, the docker image build part is working fine but I am unable to push the image through docker:push option. I read and tried other available solutions like using

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

and added registry name in .docker/.config file but it didn't worked . I also added registry but it also didn't worked.

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

The push is working by using

docker push

But its not working with the plugin. Please help me. Thanks.

We are using com.spotify docker-maven-plugin I think they aren´t much different.
Here is an example of our 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>

The username and password for the registry are set in the settings.xml
Here is an example of our settings.xml

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

I hope this can help you to get the right configuration for your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM