首页 > 解决方案 > 使用来自 Bitbucket Pipelines 的 docker-maven-plugin 将图像推送到 DockerHub

问题描述

我正在尝试设置docker-maven-pluginfabric8以便可以从 Bitbucket Pipelines 使用它。

我的 pom.xml 看起来像这样:

..
..
<plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <configuration>
                            <dockerHost>???????????</dockerHost>
                            <verbose>true</verbose>
                            <pushRegistry>true</pushRegistry>
                            <authConfig>
                                <username>username</username>
                                <password>password</password>
                            </authConfig>
                            <images>
                                <image>
                                    <registry>registry.hub.docker.com</registry>
                                    <name>${dockerhub.repository}</name>
                                    <build>
                                        <dockerFileDir>${project.basedir}</dockerFileDir>
                                        <tags>
                                            <tag>${docker.tag}</tag>
                                        </tags>
                                        <noCache>true</noCache>
                                    </build>
                                </image>
                            </images>
                        </configuration>
                        <executions>
                        ...
                      </plugin>


这在本地运行时非常有效。我在 Bitbucket Pipelines 上遇到的错误是:

[ERROR] DOCKER> Cannot create docker access object  [Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused (Connection refused)]

是的,这是因为我不确定要在<dockerHost>标签中添加什么,知道吗?是否需要做任何其他事情才能远程完成这项工作?

谢谢!

标签: bitbucket-pipelinesdocker-maven-plugin

解决方案


我遇到了同样的问题,但是在运行依赖于 docker 图像的集成测试时。经过大量搜索,我发现了以下内容

  • 有未记录的环境变量$BITBUCKET_DOCKER_HOST_INTERNAL可能对您的情况有所帮助。

  • 我选择在我的 bitbucket 管道中添加所需的 docker 图像作为服务,而不是依赖于 fabric8,如下所示

image: maven:3.8.2-jdk-11

clone:
  depth: full              # SonarCloud scanner needs the full history to assign issues properly

definitions:
  caches:
    sonar: ~/.sonar/cache  # Caching SonarCloud artifacts will speed up your build
  steps:
    - step: &build-test-sonarcloud
        name: Build, test and analyze on SonarCloud
        caches:
          - maven
          - sonar
        script:
          - mvn -f server/pom.xml -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectName=user-management
        services: 
          - redis 
          - rabbitmq
        artifacts:
          - target/**
  services: 
    redis: 
      image: redis
    rabbitmq:
      image: rabbitmq

pipelines:                 # More info here: https://confluence.atlassian.com/bitbucket/configure-bitbucket-pipelines-yml-792298910.html
  branches:
    '**':
      - step: *build-test-sonarcloud
  pull-requests:
    '**':
      - step: *build-test-sonarcloud

如这里的文档中所述

我希望这会有所帮助


推荐阅读