Installation
Host
host#prompt> docker pull ubuntu:14.04
DB Master
host#prompt> docker run -it --name dbmaster -h dbmaster ubuntu:14.04 bash
dbmaster#prompt> apt-get update
dbmaster#prompt> apt-get -y install mysql-client mysql-server vim
DB Slave
host#prompt>docker run -it --name dbslave -h dbslave --link dbmaster:dbmaster -p 8080:80 ubuntu:14.04 bash
dbslave#prompt> apt-get update
dbslave#prompt> apt-get -y install mysql-client mysql-server vim
dbslave#prompt> apt-get -y install php5 libapache2-mod-php5 php5-mcrypt apache2 php5-mysql
with docker inspect ContainerName you can see the information of the container between other things the IP, on my case:
Host
docker inspect dbmaster = 172.17.0.2
docker inspect dbslave = 172.17.0.3
Configuration
Master
Edit /etc/mysql/my.cnf se realizan las configuracion de mysql, test es el nombre de la base de datos
dbmaster#prompt> service mysql start
dbmaster#prompt> mysql -u root -p123
mysql > GRANT REPLICATION SLAVE ON *.* TO 'suser'@'%' IDENTIFIED BY 'pass';
mysql > GRANT ALL PRIVILEGES ON test.* TO ‘suser’@’%’ IDENTIFIED BY 'pass';
mysql > FLUSH PRIVILEGES;
Slave
Edit /etc/mysql/my.cnf
dbslave#prompt> service mysql restart
dbslave#prompt> mysql -u root -p123
mysql > CHANGE MASTER TO MASTER_HOST='172.17.0.2', MASTER_USER='suser', MASTER_PASSWORD='pass', MASTER_LOG_FILE='mysql-bin.000006', MASTER_LOG_POS= 107;
mysql > START SLAVE;
mysql > SHOW SLAVE STATUS\G
Apache
If you want a query on dbslave to dbmaster we can use PHP, the Mine is "consulta.php" on /var/www/html/ and start the service
dbslave#prompt> service apache2 start
Resource
http://terraltech.com/mysql-replication-setup-on-ubuntu/
https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql