docker (centOS 7) 使用笔记3 - docker swarm mode
1. 什么是docker swarm mode
docker engine自带的 容器管理 工具。功能比较早的 docker swarm 更多,且集成在docker engine里。
(docker version >= v1.12 )
2. 网络环境要求
* 节点的IP地址互相可以访问以下端口:
2377 (TCP)
7946 (TCP, UDP)
4789 (UDP)
3. 创建swarm mode流程(以1个manager,2个worker为例)
(1) 初始化第1个manager
[root@w02 ~]# docker swarm init --advertise-addr 10.10.10.100:2377
Swarm initialized: current node (64p5nlxp9ni8p2qi1hvsmvbyn) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
10.10.10.100:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
(2) 添加worker
如上提示
[root@w07 ~]# docker swarm join \ --token SWMTKN-1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \ 10.10.10.100:2377
This node joined a swarm as a worker.
执行成功后,查看状态:
[root@w07 ~]# docker info
可以看到有下面这段:
Swarm: active NodeID: 25alak1m2ow409qbbp0j4y906 Is Manager: false Node Address: 10.10.10.100
在manage节点上查看节点列表:
[root@w02 ~]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS 25alak1m2ow409qbbp0j4y906 w07 Ready Active 64p5nlxp9ni8p2qi1hvsmvbyn * w02 Ready Active Leader
添加第2个节点后:
[root@w02 shells]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS 25alak1m2ow409qbbp0j4y906 w07 Ready Active 64p5nlxp9ni8p2qi1hvsmvbyn * w02 Ready Active Leader a2fdbsq15mhcz1jeymvmlrypz w08 Ready Active
4. 启动服务(service)
docker service create \ --name=api_test \ --replicas=1 \ --limit-cpu=4 \ -p 58080:8080 \ 10.28.229.2:5000/tomcat9:apiplatform \ /root/tomcat.sh