This demo is a lightweight bash script to bring together two Docker Containers to create a replicating MySQL cluster for testing / development purposes.
It is as simple as running ./start_cluster, passing in the number of slaves you want in your cluster like so:
./start_cluster -n 2
The script will pull a master image and a slave image from the docker hub and will start one master and as many slaves as you specify, with replication set up and working out of the box.
Ideal for testing read-write splitting in your web application.
docker run --name my-master -d doug/mysql-master
The slaves will need to --link
to whatever the master’s --name
is set to
The privileged user / password is by default root / root
Override this by setting the env variables, $USERNAME and $PASSWORD:
docker run --name my-master -e "USERNAME=fuji" -e "PASSWORD=yama" -d doug/mysql-master
docker run --name my-slave1 --link my-master:my-master -e "MYSQL_MASTER_HOST=my-master" -e "SERVER_ID=1" -d doug/mysql-slave
As well as using --link
to link to the master, the MYSQL_MASTER_HOST env variable needs to be set
Each slave needs to be given a unique SERVER_ID
No need to snapshot a slave – masters can be snapshotted and new slaves will always catch up
root / root can be overridden in the same way as for a master
Slaves have a default readonly user set who only has select privileges: readonly / readonly
This username / password can be overridden by passing in the READONLY_USERNAME and READONLY_PASSWORD environment variables
- Docker
- Internet
MIT License