1. 什麼是docker swarm modenode
docker engine自帶的 容器管理 工具。功能比較早的 docker swarm 更多,且集成在docker engine裏。docker
(docker version >= v1.12 )shell
2. 網絡環境要求api
* 節點的IP地址互相能夠訪問如下端口:tomcat
2377 (TCP)網絡
7946 (TCP, UDP) 工具
4789 (UDP)this
3. 建立swarm mode流程(以1個manager,2個worker爲例)spa
(1) 初始化第1個manager code
[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