繁体   English   中英

为什么docker stack ps显示所有“期望状态”

[英]Why does docker stack ps show all “DESIRED STATE”

Docker为什么要显示每个服务的先前任务? 我只想查看具有所需状态“正在运行”的当前任务。 我想清理已移至“运行”以外的所需状态的较旧任务。 如何做到这一点?

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  

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

docker swarm update --task-history-limit 3

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM