开始使用Swarm - 删除service

优质
小牛编辑
132浏览
2023-12-01

教程剩下的部分不需要helloworld这个service了,所以我们现在可以将它删除掉。

  1. 通过ssh登录到manager节点。

  2. 运行docker service rm helloworld来删除helloworld服务(service):

    1. $ docker service rm helloworld
    2. helloworld
  3. 运行docker service inspect <SERVICE-ID>来确认service是否被删除。CLI将会返回service无法找到信息。

    1. $ docker service inspect helloworld
    2. []
    3. Error: no such service: helloworld
  4. 移除service后,task的container会在若干秒后被彻底清楚干净。可以登录到相应的节点上,运行docker ps命令来查看task是否被清理。

    1. $ docker ps
    2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    3. db1651f50347 alpine:latest "ping docker.com" 44 minutes ago Up 46 seconds helloworld.5.9lkmos2beppihw95vdwxy1j3w
    4. 43bf6e532a92 alpine:latest "ping docker.com" 44 minutes ago Up 46 seconds helloworld.3.a71i8rp6fua79ad43ycocl4t2
    5. 5a0fb65d8fa7 alpine:latest "ping docker.com" 44 minutes ago Up 45 seconds helloworld.2.2jpgensh7d935qdc857pxulfr
    6. afb0ba67076f alpine:latest "ping docker.com" 44 minutes ago Up 46 seconds helloworld.4.1c47o7tluz7drve4vkm2m5olx
    7. 688172d3bfaa alpine:latest "ping docker.com" 45 minutes ago Up About a minute helloworld.1.74nbhb3fhud8jfrhigd7s29we
    8. $ docker ps
    9. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS