docker探索-使用docker service管理swarm(十一 )
本文转自:https://www.cnblogs.com/atuotuo/p/6265541.html
1、创建一个 Docker service
$ docker service create --replicas 1 --name myhelloworld alpine ping docker.com
--replicas
: 标识运行实例个数
--name
: service 的名称
alpine ping docker.com: 运行参数,表明service将运行一个Alpine Linux container,并且执行
ping docker.com
的命令。
2、审视 Docker service
$ docker service inspect --pretty myhelloworld
--pretty: 指定返回为简约格式,否则,讲义JSON格式返回
3、查看 service 上运行 node 的情况
$ docker service ps myhelloworld
4、查看容器详细信息
$ docker ps
5、修改service 规模
$ docker service scale myhelloworld=5
6、删除 service
$ docker service rm myhelloworld
7、轮询更新
$ docker service create \
--replicas 3 \
--name redis \
--update-delay 10s \
redis:3.0.6
查看 service 状态
$ docker service inspect --pretty myredis
8、更新 service
更新节点
$ #docker service update --image redis:3.0.6 myredis
指定service的某个节点排满状态
$ docker node update --availability drain worker1
此后,将不会再在worker1 上面分派任务
9、查看swarm的存在的service列表
[root@node1 docker-compose]# docker service list ID NAME MODE REPLICAS IMAGE 6yv909v5mja6 eureka_peer3 replicated 1/1 192.168.6.132:5000/jacky/microservice-discovery-eureka-ha:1.0-SNAPSHOT m6wc4dcl0vts eureka_peer1 replicated 1/1 192.168.6.132:5000/jacky/microservice-discovery-eureka-ha:1.0-SNAPSHOT un42g3kd94en eureka_userService replicated 1/1 192.168.6.132:5000/jacky/microservice-provider-user:1.0-SNAPSHOT y8gyq056nm3f portainer replicated 1/1 portainer/portainer:latest zg53vjcj4noa eureka_peer2 replicated 1/1 192.168.6.132:5000/jacky/microservice-discovery-eureka-ha:1.0-SNAPSHOT
10、删除swarm中的服务
[root@node1 docker-compose]# docker service rm eureka_userService eureka_userService [root@node1 docker-compose]# docker service ls ID NAME MODE REPLICAS IMAGE 6yv909v5mja6 eureka_peer3 replicated 1/1 192.168.6.132:5000/jacky/microservice-discovery-eureka-ha:1.0-SNAPSHOT m6wc4dcl0vts eureka_peer1 replicated 1/1 192.168.6.132:5000/jacky/microservice-discovery-eureka-ha:1.0-SNAPSHOT y8gyq056nm3f portainer replicated 1/1 portainer/portainer:latest zg53vjcj4noa eureka_peer2 replicated 1/1 192.168.6.132:5000/jacky/microservice-discovery-eureka-ha:1.0-SNAPSHOT
注意:正在运行中的swarm 服务也是可以删除的