spotify / docker-maven-plugin

INACTIVE: A maven plugin for Docker
Apache License 2.0
2.67k stars 575 forks source link

why it always try to push to docker.io/library when i am using private registry #416

Closed QingLea closed 5 years ago

QingLea commented 5 years ago

Description

I am using private registry and when i use you plugin to push images to private registry ,but it always trying push to docker.io/library after private registry pushing was finished Here is part of my pom.xml

<plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.2.0</version>
                <configuration>
                    <imageName>monoy.cn:5000/${project.name}</imageName>
                    <baseImage>openjdk:alpine</baseImage>
                    <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                    <imageTags>
                        <imageTag>${project.version}</imageTag>
                    </imageTags>
                </configuration>
            </plugin>

IDEA LOGS

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building crypto-watch-dog-demo 0.0.2
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- docker-maven-plugin:1.2.0:push (default-cli) @ crypto-watch-dog-demo ---
[INFO] Using authentication suppliers: [ConfigFileRegistryAuthSupplier]
[INFO] Pushing monoy.cn:5000/crypto-watch-dog-demo
The push refers to repository [monoy.cn:5000/crypto-watch-dog-demo]
93351e248e6e: Preparing 
298c3bb2664f: Preparing 
73046094a9b8: Preparing 
298c3bb2664f: Layer already exists 
93351e248e6e: Layer already exists 
73046094a9b8: Layer already exists 
0.0.2: digest: sha256:fba4a728174278a55552065cebb2559be42f9d40c2db1e87c94ac59505afdf76 size: 947
null: null 
93351e248e6e: Preparing 
298c3bb2664f: Preparing 
73046094a9b8: Preparing 
73046094a9b8: Layer already exists 
93351e248e6e: Layer already exists 
298c3bb2664f: Layer already exists 
latest: digest: sha256:fba4a728174278a55552065cebb2559be42f9d40c2db1e87c94ac59505afdf76 size: 947
null: null 
[INFO] Pushing monoy.cn:0.0.2
The push refers to repository [docker.io/library/monoy.cn]
[WARNING] Failed to push monoy.cn:5000/crypto-watch-dog-demo, retrying in 10 seconds (1/5).

look the end of log , I am wandering that how it happened , Does my pom.xml setting incorrect? looking forward your reply, thank you!

zhabba commented 5 years ago

I'm experiencing the same issue.

mattnworb commented 5 years ago

I'm not seeing where in the output it shows that the image is being pushed to docker.io:

Pushing monoy.cn:5000/crypto-watch-dog-demo
The push refers to repository [monoy.cn:5000/crypto-watch-dog-demo]

could you clarify that bit?

zhabba commented 5 years ago

@mattnworb right after pushing to private repository it tries to push to docker.io It clearly visible in last 3 lines in output posted by @fatcats

[INFO] Pushing monoy.cn:0.0.2
The push refers to repository [docker.io/library/monoy.cn]
[WARNING] Failed to push monoy.cn:5000/crypto-watch-dog-demo, retrying in 10 seconds (1/5)
QingLea commented 5 years ago

@mattnworb in last 3lines

[INFO] Pushing monoy.cn:0.0.2
The push refers to repository [docker.io/library/monoy.cn]
[WARNING] Failed to push monoy.cn:5000/crypto-watch-dog-demo, retrying in 10 seconds (1/5).
QingLea commented 5 years ago

@zhabba I edited my pom file like this to avoid this issue

<groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.2.0</version>
                <configuration>
                    <imageName>${my.docker.registry.host}/${project.name}:${project.version}</imageName> 

                    <imageTags>
                        <imageTag>latest</imageTag>
                    </imageTags>
                    <baseImage>openjdk:alpine</baseImage>
                    <entryPoint>["java", "-jar", "/${project.build.finalName}.jar"]</entryPoint>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
                <executions>
                    <execution>
                        <id>build-docker-image</id>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>push-docker-image</id>
                        <phase>package</phase>
                        <goals>
                            <goal>push</goal>
                        </goals>
                    </execution>
                </executions>

<imageName>${my.docker.registry.host}/${project.name}:${project.version}</imageName> I found that if i added my project version behind image name could avoid this issue.

QingLea commented 5 years ago

I do not know this issue is a feature or a bug. Do I must set my image version to avoid it push my image to docker.io? @mattnworb

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

yulechen commented 5 years ago

I has the same issue. I see the source code :

  if (pushImageTag) {
      pushImageTag(docker, imageName, imageTags, getLog(), isSkipDockerPush());
    } 
  if (pushImage) { 
       pushImage(docker, imageName, imageTags, getLog(), buildInfo, getRetryPushCount(),
          getRetryPushTimeout(), isSkipDockerPush());
    }

pushImageTag will call this method

private static String getImageNameWithNoTag(String imageName) {
    final int tagSeparatorIndex = imageName.lastIndexOf(':');
    if (tagSeparatorIndex >= 0) {
      imageName = imageName.substring(0, tagSeparatorIndex);
    }
    return imageName;
  }

if use pushImage parameter ,the image will push to docker.io/library and retry. so my solution is not use pushImage。 only use pushImageTag。