![关注抖音创业](https://img.kancloud.cn/c5/ce/c5ced2ea291122851697114ca415ff95_1125x1680.png) [TOC] # 创建一个tomcat的service ``` > docker service create --name my-tomcat tomcat ``` # 查看当前swarm的service ``` docker service ls ``` # 查看service的启动日志 ``` docker service logs my-tomcat ``` # 查看service的详情 ``` docker service inspect my-tomcat ``` # 查看my-tomcat运行在哪个node上 ``` docker service ps my-tomcat ``` `日志` ``` ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS u6o4mz4tj396 my-tomcat.1 tomcat:latest worker01-node Running Running 3 minutes ago ``` # 水平扩展service ``` docker service scale my-tomcat=3 docker service ls docker service ps my-tomcat ``` `日志`:可以发现,其他node上都运行了一个my-tomcat的service ``` [root@manager-node ~]# docker service ps my-tomcat ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS u6o4mz4tj396 my-tomcat.1 tomcat:latest worker01-node Running Running 8 minutes ago v505wdu3fxqo my-tomcat.2 tomcat:latest manager-node Running Running 46 seconds ago wpbsilp62sc0 my-tomcat.3 tomcat:latest worker02-node Running Running 49 seconds ago ``` 此时到worker01-node上:docker ps,可以发现container的name和service名称不一样,这点要知道 ``` CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bc4b9bb097b8 tomcat:latest "catalina.sh run" 10 minutes ago Up 10 minutes 8080/tcp my-tomcat.1.u6o4mz4tj3969a1p3mquagxok ``` # 自动扩展 > 如果某个node上的my-tomcat挂掉了,这时候会自动扩展 ``` [worker01-node] docker rm -f containerid [manager-node] docker service ls docker service ps my-tomcat ``` # 删除service ``` docker service rm my-tomcat ```