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
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, use127.0.0.1
instead in Bitbucket Pipelines.Yes, the address is wrong, that’s the essence of the error message:
Just use regular pipeline services instead.
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. Usinglocalhost
in the URI should be fine. But pipeline services would take care about that for you.