Pushing image to DockerHub using docker-maven-plugin from Bitbucket Pipelines

448 views Asked by At

I'm trying to setup docker-maven-plugin by fabric8 so I can use it from Bitbucket Pipelines.

My pom.xml looks like this:

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


This works perfectly when running locally. The error I'm getting on Bitbucket Pipelines is:

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

Yeah, this is happens since I'm not sure what to put in <dockerHost> tag, any idea? Is there anything else needs to be done to make this work remotely?

Thank you!

1

There are 1 answers

0
Mohamed Serag Eldeen On

I was facing the same issue but in running Integration tests which depend on docker images. After a lot of searches I found the following

  • There's undocumented environment variable of $BITBUCKET_DOCKER_HOST_INTERNAL which maybe helpful in your case.

  • I chose to add needed docker images as services in my bitbucket pipeline instead of depend on fabric8 as the following

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

as mentioned in there documentation here

I hope this would be helpful