Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Can't access MySQL On BitBucket Cloud

I'm using the `docker` service to perform a docker run command & I am also using the `mysql` service. I can seem to connect to the mysql service from within the docker container. I keep getting "connection refused" any help?

1 answer

1 accepted

0 votes
Answer accepted

Hey @Jamie Bailey , welcome to the Atlassian Community.

No idea if I get you right here. So within your Pipeline Container (that is also a Docker container) you are running `docker run command-container ...` that should connect to the `mysql` service that is added to the pipeline step?

For illustration:

pipelines:
default:
- step:
image: ktomk/pipelines:busybox
script:
- docker run command-container ...
services:
- mysql
- docker

The pipeline container (ktomk/pipelines:busybox) can access the services (mysql) via localhost / 127.0.0.1.

This is either also possible for the command-container (use 127.0.0.1 for mysql as "localhost" can cause problems with Mysql) or not. I don't know.

In case it's not, it needs to find it's way through docker networking. So try with "127.0.0.1" and port "3306" first. If that is not possible the other option I know about (details) is to

If you need to communicate from a service running in docker to a service running in your build container, when starting the service provide it the following host entry using --add-host host.docker.internal:$BITBUCKET_DOCKER_HOST_INTERNAL you can then access the service using host.docker.internal:<port>.

this is not exactly your use-case but might give pointers on the networking layout. The post writes that using `--network=host` is not possible any longer, so for the `docker run` command it might still work to add the host hosts.docker.internal as outlined and then the mysql service could be available on host.docker.internal and port 3306. 

Hey @ktomk 

Forgot to update, I found the solution. So while inside the container I was trying to communicate with the MariaDB/MySQL server using 127.0.0.1 & localhost and this did not work.

To access the host network on BitBucket cloud from within a docker container I used 172.17.0.1

`172.17.0.1` is the default docker-ip. It may change and then it breaks.

Better would be to do the suggested internal host resolution with the Bitbucket Pipelines environment variable:

docker run --add-host host.docker.internal:"$BITBUCKET_DOCKER_HOST_INTERNAL" ...

 and then use `host.docker.internal` instead of `172.17.0.1`.

You could also `echo "$BITBUCKET_DOCKER_HOST_INTERNAL"` in a pipeline script line to see what this standard variable contains.

Like Jamie Bailey likes this

@ktomk thank you for the help, that worked.

I did it slightly differently:

docker run --env DB_TEST_HOST=$BITBUCKET_DOCKER_HOST_INTERNAL ...

since our docker app uses this environment variable to access the MariaDB host

Like ktomk likes this

Yes, exactly that way. Looks good to me. And great to read how it resolved.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across Jira Cloud instance.   📢 Get y...

23 views 0 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you