如何解决使用Maven将Docker Image推送到私有存储库时的身份validation问题

我试图推动我的Docker镜像,这是我在本地使用maven构build到我的公共/私人存储库在Docker云/ Docker Hub.But我得到索引响应不包含任何端点时,它试图Push.Below是样本我的pom.xml的configuration。

我不知道我错过了哪个configuration。

<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.11</version> <configuration> <imageName>${docker.image.prefix}/dockercloudappstation</imageName> <dockerDirectory>src/main/docker</dockerDirectory> <!-- <dockerHost>tcp://192.168.99.100:2376</dockerHost> --> <serverId>docker-hub</serverId> <!-- <registryUrl>https://hub.docker.com/</registryUrl> --> <resources> <resource> <!-- <targetPath>/</targetPath> --> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> <executions> <execution> <id>build-image</id> <phase>package</phase> <goals> <goal>build</goal> </goals> </execution> <execution> <id>tag-image-version</id> <phase>package</phase> <goals> <goal>tag</goal> </goals> <configuration> <!-- <image>${docker.image.prefix}/${project.artifactId}</image> --> <image>${docker.image.prefix}/dockercloudappstation</image> <newName>hub.docker.com/${docker.image.prefix}/dockercloudappstation</newName> <!-- <serverId>docker-hub</serverId> --> <pushImage>true</pushImage> </configuration> </execution> <execution> <id>tag-image-latest</id> <phase>package</phase> <goals> <goal>tag</goal> </goals> <configuration> <!-- <image>${docker.image.prefix}/${project.artifactId}</image> --> <image>${docker.image.prefix}/dockercloudappstation</image> <newName>hub.docker.com/${docker.image.prefix}/dockercloudappstation:latest</newName> <pushImage>true</pushImage> </configuration> </execution> <execution> <id>push-image</id> <phase>package</phase> <goals> <goal>push</goal> </goals> <configuration> <serverId>docker-hub</serverId> <!-- <imageName>${docker.image.prefix}/dockercloudappstation</imageName> --> </configuration> </execution> 

错误日志:

  at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: org.apache.maven.plugin.MojoExecutionException: Exception caught at com.spotify.docker.AbstractDockerMojo.execute(AbstractDockerMojo.java:130) at com.spotify.docker.TagMojo.execute(TagMojo.java:44) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207) ... 20 more Caused by: com.spotify.docker.client.exceptions.DockerException: Index response didn't contain any endpoints at com.spotify.docker.client.AnsiProgressHandler.progress(AnsiProgressHandler.java:52) at com.spotify.docker.Utils$DigestExtractingProgressHandler.progress(Utils.java:150) at com.spotify.docker.client.ProgressStream.tail(ProgressStream.java:77) at com.spotify.docker.client.DefaultDockerClient.push(DefaultDockerClient.java:1040) at com.spotify.docker.Utils.pushImage(Utils.java:83) at com.spotify.docker.TagMojo.execute(TagMojo.java:119) at com.spotify.docker.AbstractDockerMojo.execute(AbstractDockerMojo.java:128) 

打开您的Maven设置configurationsettings.xml ,并添加您的凭据在这里服务器。 通常这个文件位于.m2文件夹中,所以在这里添加如下内容:

 <servers> <server> <id>docker-hub</id> <username>username</username> <password>password</password> </server> </servers> 

由于安全问题,这个设置不应该是(而AFAIK不能)在pom.xml中。

如果你对更安全的选项感兴趣,你可以像这里的例子一样encryption你的密码。


你有太麻烦的pom.xml 。 尝试从最简单的pom.xmlconfiguration开始。 检查springio示例 ,并将springio属性更改为springio docker hub回购。

 <properties> <docker.image.prefix>springio</docker.image.prefix> </properties> <build> <plugins> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.11</version> <configuration> <imageName>${docker.image.prefix}/${project.artifactId}</imageName> <dockerDirectory>src/main/docker</dockerDirectory> <serverId>docker-hub</serverId> <!-- <registryUrl></registryUrl> is optional and defaults to https://index.docker.io/v1/ in the Spotify docker-client dependency. --> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jar</include> </resource> </resources> </configuration> </plugin> </plugins> </build>