如何停止 docker 服务?

新手上路,请多包涵

如何停止 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

原文由 DenCowboy 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 362
2 个回答

在 Docker 中,“服务”的概念表示代表一堆容器抽象的资源。它可以存在或不存在,但您不能“运行”服务。您只能运行容器。因此,您也不能“停止”服务,只能将其删除。

原文由 anothernode 发布,翻译遵循 CC BY-SA 4.0 许可协议

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 ~
$

原文由 person one 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏