如何在滚动更新后删除关闭Docker服务任务?

时间:2017-01-17 19:12:23

标签: docker containers docker-swarm

我正在使用Docker Swarm来测试AWS上的服务。我最近对此服务应用了这样的更新:

 docker service update --image TestImage:v2 --update-parallelism 2 \
--update-delay 10s TestService2

更新按预期工作,服务将任务容器更新为v2。但是,快速docker service ps TestService2 | grep "v1"会显示一系列关闭TestImage:v1任务。

a0w77kj0k6jfg4r9g4nz47zzg   \_ TestService2.1   TestImage:v1  W1  Shutdown       Shutdown 36 minutes ago
2of4mc63ekzbib01w3x7q6sdm   \_ TestService2.2   TestImage:v1  W2  Shutdown       Shutdown 37 minutes ago
495frrpza5pxt205o1594x54a   \_ TestService2.3   TestImage:v1  W1  Shutdown       Shutdown 36 minutes ago
57l0gsqd26u2e5gdj30w8mcn9   \_ TestService2.4   TestImage:v1  M1  Shutdown       Shutdown 36 minutes ago
baoe1i79fswb34ydwbpafg6tm   \_ TestService2.5   TestImage:v1  M3  Shutdown       Shutdown 35 minutes ago
3uxi7kwxb73z69km6s17son58   \_ TestService2.6   TestImage:v1  M2  Shutdown       Shutdown 37 minutes ago
99cg4arnt1y52nd8d422bdu49   \_ TestService2.7   TestImage:v1  M3  Shutdown       Shutdown 36 minutes ago
cq5716jqp40h6jugo1j9ilzwp   \_ TestService2.8   TestImage:v1  M1  Shutdown       Shutdown 35 minutes ago
awlz1kxbrjk51dey7frm14d8u   \_ TestService2.9   TestImage:v1  W3  Shutdown       Shutdown 35 minutes ago
4xdi9a1jweyehfqlt76uynf3i   \_ TestService2.10  TestImage:v1  M2  Shutdown       Shutdown 36 minutes ago
eo4t6i0gaj5i294fcdnb3qncq   \_ TestService2.11  TestImage:v1  W3  Shutdown       Shutdown 35 minutes ago
3ydeuxdjquulv5xj94b9ovuwu   \_ TestService2.12  TestImage:v1  W1  Shutdown       Shutdown 36 minutes ago

如何在不去往每个单独的swarm节点并在已退出的容器上运行docker rm的情况下删除它们?我不认为这是docker service命令,我查看了文档,但有没有人知道我可以在Swarm Manager上运行的hack或脚本来清理节点?

谢谢!

2 个答案:

答案 0 :(得分:16)

滚动更新后,将删除这些服务的容器;你只需要留下那些被关闭的日志。

您可以使用

限制您看到的数字
    CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__:
    0x187012b44 <+0>:  mov    x8, x0
    0x187012b48 <+4>:  cbz    x8, 0x187012b60           ; <+28>
    0x187012b4c <+8>:  stp    x29, x30, [sp, #-16]!
    0x187012b50 <+12>: mov    x29, sp
    0x187012b54 <+16>: mov    x0, x1
    0x187012b58 <+20>: blr    x8
->  0x187012b5c <+24>: ldp    x29, x30, [sp], #16
    0x187012b60 <+28>: ret   

答案 1 :(得分:1)

yi92mgl7z8jb        web.2               nginx:latest        manager1            Running             Running 11 minutes ago
0cmzbd1oxwqr         \_ web.2           nginx:latest        manager1            Shutdown            Failed 11 minutes ago     "task: non-zero exit (255)"
moe7hex4qvmg         \_ web.2           nginx:latest        manager1            Shutdown            Shutdown 11 minutes ago
iyxs118uo67d         \_ web.2           nginx:latest        manager1            Shutdown            Shutdown 10 hours ago
v3uxafpxc4d3         \_ web.2           nginx:latest        manager1            Shutdown            Shutdown 11 minutes ago
6upsy8gvyrsn        web.5               nginx:latest        manager1            Running             Running 11 minutes ago
mlaxkfusunqe         \_ web.5           nginx:latest        manager1            Shutdown            Failed 11 minutes ago     "task: non-zero exit (255)"
bh3nkp05yd6r         \_ web.5           nginx:latest        manager1            Shutdown            Shutdown 11 minutes ago
lqedayxq7gr9         \_ web.5           nginx:latest        manager1            Shutdown            Shutdown 10 hours ago
xryxpfjsrdja         \_ web.5           nginx:latest        manager1            Shutdown            Shutdown 11 minutes ago

我做到了

docker swarm update --task-history-limit 2

docker-machine stop manager1

docker-machine start manager1

PS C:\> docker service ps web | Select-String "manager1"

3ogu1r0y6s6t        web.2               nginx:latest        manager1            Running             Running 3 minutes ago
0cmzbd1oxwqr         \_ web.2           nginx:latest        manager1            Shutdown            Failed 3 minutes ago      "task: non-zero exit (255)"
wbxr5hubftfa        web.5               nginx:latest        manager1            Running             Running 3 minutes ago
bh3nkp05yd6r         \_ web.5           nginx:latest        manager1            Shutdown            Shutdown 25 minutes ago

谢谢Geige V