maven - 使用 Maven 将 Docker 镜像推送到私有(private)存储库时如何解决身份验证问题

标签 maven docker spring-boot-maven-plugin

我正在尝试将我在本地使用 maven 构建的 docker 镜像推送到 Docker Cloud/Docker Hub 中的公共(public)/私有(private)存储库。但是当它尝试推送时,我得到的索引响应不包含任何端点。下面是示例我的 pom.xml 的配置。

我不确定我在这里缺少哪个配置。

    <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)

最佳答案

打开settings.xml为您的 Maven 设置配置并在此处添加带有您的凭据的服务器。通常此文件位于 .m2文件夹,所以在这里添加类似:

<servers>
  <server>
    <id>docker-hub</id>
    <username>username</username>
    <password>password</password>
  </server>
</servers>
pom.xml 中不应有此设置(并且 AFAIK 也不能有)因为安全问题。

如果您对更安全的选项感兴趣,您可以加密您的密码,例如 here .

你太乱了pom.xml .尝试从最简单的 pom.xml 开始配置。查看springio example并更改 springio属性(property)到您的docker hub repo 。
<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>

关于maven - 使用 Maven 将 Docker 镜像推送到私有(private)存储库时如何解决身份验证问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40458608/

相关文章:

java - 有没有办法在依赖项中强制执行编译器目标版本?

docker - 在 Docker 中使用多个 Base Image 有什么影响?

linux - 主管 : Stop the Docker container when a process crashes

java - 如何使用应用程序属性和 pom 文件共享/传递变量

java - Spring Boot中的多模块依赖管理问题

maven - 在构建生命周期之外分发/使用 Maven 项目的推荐做法

eclipse - Merve 在每次启动 Tomcat 时构建 Maven 项目

java - Apache Spark 在 IntelliJ 中给出错误

linux - 如何使用 CoreOS 的云配置文件启动 Docker 容器?

java - 使用 requiresUnpack 使用 Maven 构建的 Spring Boot JAR 不起作用