Recommend: http://www.hawu.me/operation/802
1. docker-machine 建立三台虚拟机,first,second,third,third is a worker and the other
two are managers as the following picture.
2.
You can also encrypt data exchanged between containers on different nodes on the overlay network. To enable encryption, when you create an overlay network pass the –opt encrypted flag:
$ docker network create --opt encrypted --driver overlay myapp
When you enable overlay encryption, Docker creates IPSEC tunnels between all the nodes where tasks are scheduled for services attached to the overlay network. These tunnels also use the AES algorithm in GCM mode and manager nodes automatically rotate the keys every 12 hours.
建立overlay 网络myapp方便跨主机容器通信,–opt encrypted为加密,可不加。
3.
use command on manager node :
docker service create --network myapp --name redis-1 -p 7001:6379 redis
可以用docker service scale = 3
把任务副本调到3个,默认为1;
4.
docker service ps redis-1
查看service在哪些nodes上运行,发现second上有运行
5.
之后进入second容器docker exec -it 1a040a45302c /bin/bash
6.
然后docker@second:~$ redis-cli -h 192.168.99.101 -p 7001
可以自己连接,也可以通过其他主机连接second.(方式一样,进入redis容器,然后主机连接second主机的7001端口即可。)
root@1a040a45302c:/data# redis-cli -h 192.168.99.101 -p 7001
192.168.99.101:7001> set abc 123
OK
192.168.99.101:7001> get abc
"123"