Operating environment
- The IPs of the two virtual machines are: 192.168.0.103 (referred to as: A host), 192.168.0.104 (referred to as: B host)
- Operating System: Centos 7
- Docker version: 1.8
Mysql mirror configuration
1. Download the mirror mysql in the two hosts A and B: docker pull mysql
2. Create a container test1 in host A (docker create –name=test1 –it mysql /bin/bash)
3. Create container test2 in host B (docker create –name=test2 –it mysql /bin/bash)
4. Modify the network address of docker0 on host B so that it does not conflict with docker0 on host A
vi /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/docker daemon --bip=172.18.42.1/16 -H fd:// -H=unix:///var/run/docker.sock
Execute the command: systemctl daemon-reload
Then restart B host
B host network information:
routing settings
Execute route add -net 172.17.0.0/16 gw 192.168.0.103 on host B
Execute route add -net 172.18.0.0/16 gw 192.168.0.104 on host A
Firewall settings
iptables -F ; iptables -t nat –F
Container IP information
test1 container IP: 172.18.0.1, test2 container IP: 172.17.0.1
Container test1 information
container test2 information
Intercommunication between containers
test1 ping test2
test2 ping test1
Mysql connection
1. Test2 connects to the mysql service in test1
2. Start the mysql service in test1: service start mysql
3. Create the chenx database in the test1 container.
4、执行:GRANT ALL PRIVILEGES ON chenx.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Make the chenx library remotely accessible under the root user;
http://www.cnblogs.com/jianyuan/p/5050409.html