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

docker-compose, mysql and bitbucket pipelines - how to make them play nicely

Chris Smith February 20, 2020

I have a build step which

  • Installs docker-compose
  • runs docker-compose up to create
    • an api, connected to a
    • mysql container
    • test runner (newman container which calls the API)
  • Installs test data into the mysql container
  • runs a docker exec command on the test runner to kick off the tests against the api

Now, I have attempted to spin this up, by the mysql container fails when I try to install test data into it, because of the following error message is returned:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I am assuming this error message is related to the way bitbucket pipelines handles mysql as a service, so my container can't connect accordingly to the above socket.

I then read about spinning up a mysql service in my bitbucket pipelines step, which I did.  I was able to get my sample data loaded into the local mysql  database.  However, as my containerised API needs to access this mysql instance for its data, I was unable to work out the correct way to make the API even find the step's mysql server to use as its data store.  The mysql service runs on 127.0.0.1, but that doesn't work for a containerised app, as it has its own idea of what 127.0.0.1 means (aka itself).

1. Is it possible in any way to spin up my own mysql container as defined in my docker-compose file, and if so, how? If not
2. How can my containerised API access the step's mysql service, as this is running on 127.0.0.1?

 

1 answer

1 accepted

2 votes
Answer accepted
Chris Smith February 25, 2020

Okay, I hope this helps anyone else.  After scouring Atlassian's community and blog posts, I discovered some undocumented "features" to their mysql implementation, and how you can allow your docker-compose (or just plain docker) app to access the step's MySQL service.

https://medium.com/it-dead-inside/bitbucket-pipelines-docker-compose-and-database-hosting-9c81aa9311f3

Hope this helps someone.  It  took me forever to figure this one out.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events