Spring Boot 3.2.x + Gradle + `bootBuildImage` + bitbucket-pipelines = `Docker API 'localhost:2375/v1.24/containers/create' 失败 403“禁止”`

问题描述 投票:0回答:1

我已将 bitbucket-pipeslines.yml 精简为重现该问题的最小示例:

pipelines:
  default:
    - step:
        name: Build
        image: gradle:8.7-jdk21
        services:
          - docker
        script:
          - gradle bootBuildImage

这会导致错误:

Execution failed for task ':bootBuildImage'.
> Docker API call to 'localhost:2375/v1.24/containers/create' failed with status code 403 "Forbidden"

如果我根据建议添加额外的管道步骤:

export DOCKER_HOST=tcp://172.17.0.1:2375
我收到类似的错误:

Execution failed for task ':bootBuildImage'.
> Docker API call to '172.17.0.1:2375/v1.24/containers/create' failed with status code 403 "Forbidden"

我正在使用 Spring Boot 3.2.4,这是撰写本文时的最新版本。我的项目主要是由 https://start.spring.io/

自动生成的

顺便说一句,在我的本地笔记本电脑上,

gradle bootBuildImage
工作正常,但在 bitbucket-pipelines 环境中,正如所讨论的那样,它失败了。

我期待形象建设能够发挥作用。

spring-boot bitbucket-pipelines
1个回答
0
投票

您可能会遇到此 Spring Boot 问题中记录的问题:https://github.com/spring-projects/spring-boot/issues/28387.

如图所示,需要与此类似的配置来解决 BitBucket Docker 配置的限制:

tasks.named('bootBuildImage') {
    docker {
        host = "tcp://172.17.0.1:2375"
        bindHostToBuilder = true
        buildWorkspace {
            bind {
                source = "/opt/atlassian/bitbucketci/agent/build/cache-${project.name}.work"
            }
        }
        buildCache {
            bind {
                source = "/opt/atlassian/bitbucketci/agent/build/cache-${project.name}.build"
            }
        }
        launchCache {
            bind {
                source = "/opt/atlassian/bitbucketci/agent/build/cache-${project.name}.launch"
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.