为什么docker stack ps显示所有" DESIRED STATE"

时间:2018-06-15 12:55:25

标签: docker

为什么Docker会显示每项服务的上一个任务?我想只看到当前任务处于所需状态" Running"。我希望清理已经移动到除#34; Running"之外的所需状态的旧任务。如何实现这一目标?

rus@coder:~/Docker$ docker stack ps getstartedlab 
ID                  NAME                         IMAGE                             NODE                DESIRED STATE       CURRENT STATE                     ERROR                              PORTS
gp07knn0g5hl        getstartedlab_redis.1        redis:latest                      myvm1               Ready               Assigned less than a second ago                                      
m31cmdrsoxns         \_ getstartedlab_redis.1    redis:latest                      myvm1               Shutdown            Rejected less than a second ago   "invalid mount config for type…"   
zjxzlx4hd5um         \_ getstartedlab_redis.1    redis:latest                      myvm1               Shutdown            Rejected 39 seconds ago           "invalid mount config for type…"   
zpi3nlsc338g         \_ getstartedlab_redis.1    redis:latest                      myvm1               Shutdown            Rejected 2 minutes ago            "invalid mount config for type…"   
xqpdhsyw54uh        getstartedlab_web.1          motionrus/get-started:part2       myvm1               Running             Running 7 minutes ago                                                
jruvttjnvwn6        getstartedlab_visualizer.1   dockersamples/visualizer:stable   myvm1               Running             Running 7 minutes ago                                                
g0f28ldwvftr        getstartedlab_web.1          motionrus/get-started:part2       myvm1               Shutdown            Failed 8 minutes ago              "No such container: getstarted…"   
zwn1mr6dsafs        getstartedlab_redis.1        redis:latest                      myvm1               Shutdown            Rejected about an hour ago        "invalid mount config for type…"   
zoi4p8rt0lmg         \_ getstartedlab_redis.1    redis:latest                      myvm1               Shutdown            Rejected about an hour ago        "invalid mount config for type…"   
czsb4iu1vx7b        getstartedlab_web.1          motionrus/get-started:part2       myvm2               Shutdown            Shutdown 6 minutes ago                                               
oavyu08f2zpy        getstartedlab_visualizer.1   dockersamples/visualizer:stable   myvm1               Shutdown            Failed 8 minutes ago              "No such container: getstarted…"   
ihisx81pn0jm        getstartedlab_web.2          motionrus/get-started:part2       myvm1               Running             Running 7 minutes ago                                                
8fvkdyyzga5u         \_ getstartedlab_web.2      motionrus/get-started:part2       myvm1               Shutdown            Failed 8 minutes ago              "task: non-zero exit (255)"        
usotwci097ll         \_ getstartedlab_web.2      motionrus/get-started:part2       myvm2               Shutdown            Shutdown 6 minutes ago                                               
js15t9lz0fip        getstartedlab_web.3          motionrus/get-started:part2       myvm1               Running             Running 7 minutes ago                                                
we3brrn188ex         \_ getstartedlab_web.3      motionrus/get-started:part2       myvm1               Shutdown            Failed 8 minutes ago              "task: non-zero exit (255)"        
ed94zf05jnqq        getstartedlab_web.4          motionrus/get-started:part2       myvm1               Running             Running 7 minutes ago                                                
p9ntyj4fl0dw         \_ getstartedlab_web.4      motionrus/get-started:part2       myvm1               Shutdown            Failed 8 minutes ago              "task: non-zero exit (255)"        
ipqdt5h8yb7p         \_ getstartedlab_web.4      motionrus/get-started:part2       myvm2               Shutdown            Shutdown 6 minutes ago                                               
s2vdxejisg0d        getstartedlab_web.5          motionrus/get-started:part2       myvm1               Running             Running 7 minutes ago                                                
yj4l496k8dky         \_ getstartedlab_web.5      motionrus/get-started:part2       myvm1               Shutdown            Failed 8 minutes ago              "task: non-zero exit (255)"        

我知道,我使用grep命令,但它不是最佳解决方案

rus@coder:~/Docker$ docker stack ps getstartedlab | grep "Running"
xqpdhsyw54uh        getstartedlab_web.1          motionrus/get-started:part2       myvm1               Running             Running 21 minutes ago                                               
jruvttjnvwn6        getstartedlab_visualizer.1   dockersamples/visualizer:stable   myvm1               Running             Running 21 minutes ago                                               
ihisx81pn0jm        getstartedlab_web.2          motionrus/get-started:part2       myvm1               Running             Running 21 minutes ago                                               
js15t9lz0fip        getstartedlab_web.3          motionrus/get-started:part2       myvm1               Running             Running 21 minutes ago                                               
ed94zf05jnqq        getstartedlab_web.4          motionrus/get-started:part2       myvm1               Running             Running 21 minutes ago                                               
s2vdxejisg0d        getstartedlab_web.5          motionrus/get-started:part2       myvm1               Running             Running 21 minutes ago  

2 个答案:

答案 0 :(得分:3)

Docker列出与堆栈关联的每个容器/任务。您可以使用过滤器来仅获取应该运行的过滤器。如果您想要保留更多或更少的容器,可以选择调整每个服务的任务历史记录。这可以在安装期间设置或使用以下命令更新:

docker swarm update --task-history-limit 3

答案 1 :(得分:1)

要查看仅根据官方documentation运行的任务,需要使用过滤器标记-f。 在您的情况下,它将是docker stack ps -f "desired-state=running" getstartedlab