Template for a seeded dockerized MySQL database using Docker Compose
Main goal of this template is to provide an easy way to setup a seeded database from an existing database for local testing and development.
See: https://github.com/docker-library/docs/tree/master/mysql#initializing-a-fresh-instance
Make sure you have Docker Desktop and Docker Compose installed.
To create and start the container:
docker-compose up
To start in detached mode:
docker-compose up -d
Since this uses the
MYSQL_RANDOM_ROOT_PASSWORDenv variable, you can get the generated password by searchingGENERATED ROOT PASSWORDin the logs. If detached mode is used, you can use Docker Desktop to view the logs of the created container.
To stop:
docker-compose down
Place your database dump inside the init/ folder.
Use
mysqldumpto generate a database dump file, or if you're using Workbench, you can use theData Exporttool inAdministration.
This config uses the mysql:latest image, but you can change it. See the supported tags here.
This config uses the default port of 3306 but you can change the XXXX in XXXX:3306 with whatever you want. You might want to provide a different port if there's already a running MySQL Server instance on your machine.
This config only uses the MYSQL_RANDOM_ROOT_PASSWORD, but if you want to specify your own password, replace it with MYSQL_ROOT_PASSWORD=yourpassword.
Other environment variables can be found here.
MYSQL_DATABASE,MYSQL_USER, andMYSQL_PASSWORDwill conflict with this seeded database setup.