MySQL is a widely used open source relational database management system. By using a MySQL container, your build process can run against an actual database, allowing for more complex and accurate testing.
The MySQL service uses the default MySQL Docker image. While this image supports a handful of configuration options, the one requirement is
MYSQL_ROOT_PASSWORD. As the name implies, this environment variable defines the password for the root MySQL account, which you can then use to access your database from within your application:
build: services: - id: mysql env: MYSQL_ROOT_PASSWORD: password box: id: php steps: # build the project
Beyond MYSQL_ROOT_PASSWORD, there are a few other useful optional environment variables that can be passed as well:
Once booted, several environment variables will be made available during the build process. The naming convention behind these variables can be found on the Service Container Networking page.
MYSQL_ENV_MYSQL_ROOT_PASSWORD=password MYSQL_NAME=/wercker-pipeline-023ebb1f-5571-44d4-97ba-cb7b68e91274/mysql MYSQL_PORT=tcp://172.XX.X.XX:3306 MYSQL_PORT_3306_TCP=tcp://172.X.X.X:3306 MYSQL_PORT_3306_TCP_ADDR=172.X.X.X MYSQL_PORT_3306_TCP_PORT=3306 MYSQL_PORT_3306_TCP_PROTO=tcp
MySQL Docker images occasionally have issues starting the database in time. You can read more about this issue in Docker’s official documentation. A common strategy for addressing it is to add a small delay in your build process in order to ensure that MySQL is up and running.
Read more about the MySQL Docker image on Docker Hub.