【问题标题】:Maven Spring Boot Cannot Push Docker ImageMaven Spring Boot 无法推送 Docker 镜像
【发布时间】:2021-02-27 02:54:11
【问题描述】:

使用 Spring Boot 2.4.0,我正在尝试配置 spring-boot:build-image 任务以将图像推送到我的私有 GitHub 容器注册表。

我使用these instructions来配置我的POM如下:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <image>
                        <name>ghcr.io/abc/${project.artifactId}:${project.version}</name>
                        <publish>true</publish>
                    </image>
                    <docker>
                        <publishRegistry>
                            <username>abc</username>
                            <token>mytoken</token>
                            <url>https://ghcr.io</url>
                        </publishRegistry>
                    </docker>
                </configuration>
            </plugin>

当我执行spring-boot:build-image 任务时,它会构建图像,但在尝试推送时出现以下错误:

[INFO] Successfully built image 'ghcr.io/abc/def:1.5.0'
[INFO]
[INFO]  > Pushing image 'ghcr.io/abc/def:1.5.0' 100%
Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.0:build-image failed: Error response received when pushing image: error parsing HTTP 405 response body: unexpected end of JSON input: "" -> [Help 1]

我可以使用docker push 手动推送图像,并且我尝试过使用docker login 也无济于事。我也不在任何防火墙或代理后面。

【问题讨论】:

    标签: spring-boot docker spring-boot-maven-plugin


    【解决方案1】:

    万一其他人发现这个问题,问题最终是 maven 插件配置中的一个错字。我使用的是&lt;token&gt; 而不是&lt;password&gt;。以下是有效的正确 XML:

                    <docker>
                        <publishRegistry>
                            <username>abc</username>
                            <password>mytoken</password>
                            <url>https://ghcr.io</url>
                        </publishRegistry>
                    </docker>
    

    【讨论】:

    • 我配置了一个没有任何身份验证的私有存储库。如果我没有指定用户名/密码字段,我会收到错误消息“无效的 Docker 发布注册表配置,必须提供令牌或用户名/密码”。有什么建议吗?
    • 是的,他们的源代码当然期望其中之一:github.com/spring-projects/spring-boot/blob/…
    • 我会在他们的 GitHub 页面上打开一个问题。我想不出他们需要一个或另一个的原因(除了安全最佳实践)。
    • 感谢您的意见。我创建了一个问题。在相关说明中,您的项目是否有 jenkins 管道?我正在尝试创建一个,但在通过管道创建 docker 映像时被阻止。搜索参考管道脚本。谢谢!
    • 在这种情况下,我还没有集成到 Jenkins 管道中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 2020-04-06
    • 2018-08-18
    • 1970-01-01
    • 2021-11-22
    • 2021-12-03
    • 1970-01-01
    相关资源
    最近更新 更多