How can I stop a docker service without removing (rm) it?
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 33 Answers
docker service scale [servicename]=0 will remove all running instances but still keep the service object alive.
eg.
[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 ~ $ 1In Docker, the concept of a "service" signifies a resource that represents an abstraction of a bunch of containers. It can exist or not exist, but you can't "run" a service. You can only run containers. Therefore you can't "stop" a service either, you can only remove it.
The service defines a target state. So rather than stopping and starting the service, if you want to stop the deployed containers without deleting the service, you would change the target state to be one where no containers would run. For a replicated service, setting the replica count to 0 works well, and for a global service, adding a constraint that is not matched on any node would work:
docker service update --replicas 0 $service_name docker service update --constraint-add no_such_node=true $service_name To delete the service, which stops all deployed containers, you run:
docker service rm $service_name 0