Connecting to MySQL in container

For my pipeline, I am pulling down the docker image tutum/lamp  to provide a full stack to test against. One of my pipeline steps is to create the various databases I need. However, the commands I am issuing fail with this message:

$ mysql --user=root --port=3306 --host=localhost < sql_scripts/create_app_dbs.sql

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


If I pull this docker image locally, run it, and ssh into it, I can execute mysql --user=root --port=3306 --host=localhost and connect without issue. Stumped as to why this is happening. From the documentation, it seems like the steps should be running inside the container, but this error makes me feel like it might be running outside of the container.


EDIT: Digging in deeper, it appears the docker run invocation is different than what I do locally. When I run it, a series of scripts initiated by the Dockerfile brings up MySQL, but the pipelines process does not run these.

2 answers

1 accepted

1 votes

You are right about Bitbucket Pipelines not running You can run it inside of your build instead.

Try the following bitbucket-pipelines.yml:

image: tutum/lamp
        - step:
                - bash / & # Start the MySQL, is located in root directory
                - sleep 20 # So that MySQL has time to start up.
                - mysql --user=root --port=3306 --host=localhost < sql_scripts/create_app_dbs.sql

Had tried running in various ways, but the bash in front finally did the trick.

Much obliged.


I suppose you could execute those same series of scripts yourself in your pipelines yml?

Suggest an answer

Log in or Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

658 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot