如何在不删除docker service
的情况下停止rm
?
Commands:
create Create a new service
inspect Display detailed information on one or more services
logs Fetch the logs of a service or task
ls List services
ps List the tasks of one or more services
rm Remove one or more services
rollback Revert changes to a service's configuration
scale Scale one or multiple replicated services
update Update a service
答案 0 :(得分:8)
docker service scale [servicename]=0
将删除所有正在运行的实例,但仍使服务对象保持活动状态。
例如
[node1] (local) root@192.168.0.8 ~
$ docker service create --name test-service nginx
cjvbwuhjhwpixwg01nh22cqbq
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converged
[node1] (local) root@192.168.0.8 ~
$ docker service scale test-service=0
test-service scaled to 0
overall progress: 0 out of 0 tasks
verify: Service converged
[node1] (local) root@192.168.0.8 ~
$ docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
cjvbwuhjhwpi test-service replicated 0/0 nginx:latest
[node1] (local) root@192.168.0.8 ~
$
答案 1 :(得分:3)
在Docker中,“服务”的概念表示代表一堆容器的抽象的资源。它可以存在或不存在,但是您不能“运行”服务。您只能运行容器。因此,您也不能“停止”服务,而只能将其删除。
答案 2 :(得分:0)
服务定义目标状态。因此,如果您要停止已部署的容器而不删除服务,而不是停止和启动服务,则可以将目标状态更改为不运行任何容器的状态。对于复制服务,将副本数设置为0很好,对于全局服务,添加在任何节点上都不匹配的约束将起作用:
docker service update --replicas 0 $service_name
docker service update --constraint-add no_such_node=true $service_name
要删除将停止所有已部署容器的服务,请运行:
docker service rm $service_name