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.
docker-machine 建立三台虚拟机,first,second,third,third is a worker and the other two are managers.

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"
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐