skip to Main Content

My Maven Java project needs to execute integration test in the following Bitbucket pipeline:

learn-pipeline:
  - step:
      name: purpose merely learning about how pipeline is working
      services:
        - docker
      script:
        - docker run --detach --name some-mariadb --env MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1 --env MARIADB_DATABASE=test mariadb:latest
        - docker ps
        - mvn clean verify

The first script is docker run to start a MariaDB container for the integration test to use. The last script mvn clean verify is to run the integration test, which is accessing to the MariaDB docker container

This Bitbucket pipeline is able to start the MariaDB Docker container, but problem is that the integration test is not able to access to the MariaDB database though jdbc:mysql://localhost:3306/test with error Caused by: java.net.ConnectException: Connection refused

Question: How to successfully access to the MariaDB Docker Container? is the jdbc address I defined wrong?

2

Answers


  1. How to successfully access to the MariaDB Docker Container?

    Do not use the socket to connect to the MariaDB server but the IPv4 or IPv6 address (localhost is socket on Linux), Network is (was?) host network, use 127.0.0.1 instead in Bitbucket Pipelines.

    [… I]s the jdbc address I defined wrong?

    Yes, the address is wrong, that’s the essence of the error message:

    Caused by: java.net.ConnectException: Connection refused

    Login or Signup to reply.
  2. Just use regular pipeline services instead.

    definitions:
      services:
        mariadb:
          image: mariadb:latest
          variables:
            MARIADB_DATABASE: test
            MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: 1
    
    pipelines:
      default:
        - step:
            name: Test
            services:
              - mariadb
            script:
              - mvn clean verify
    

    Accessing a detached docker process should also work, but most probably you simply forgot to expose the database port in the docker run --publish=3306:3306 whatnot instruction. Using localhost in the URI should be fine. But pipeline services would take care about that for you.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search