“docker node ps”输出中的任务层次结构意味着什么?

时间:2017-03-31 14:42:59

标签: docker

我有一个小型django应用程序在3节点docker swarm中运行。当我运行docker node ps时,我得到的输出类似于以下内容:

user@host$ docker node ps $(docker node ls --quiet) --filter desired-state=Running
ID            NAME                    IMAGE                                                  NODE          DESIRED STATE  CURRENT STATE               ERROR  PORTS
vn2ruaqk503o  proj1_pubsub.1          redis:3.2-alpine                                       proj1-node    Running        Running about a minute ago         
vn2ruaqk503o   \_ proj1_pubsub.1      redis:3.2-alpine                                       proj1-node    Running        Running about a minute ago         
vn2ruaqk503o   \_ proj1_pubsub.1      redis:3.2-alpine                                       proj1-node    Running        Running about a minute ago         
5njupphqr1tu  proj1_db.1              postgres:9.6-alpine                                    proj1-node-3  Running        Running about a minute ago         
ld6w8owhu3ct  proj1_app.1             python:alpine                                          proj1-node    Running        Running about a minute ago         
ld6w8owhu3ct   \_ proj1_app.1         python:alpine                                          proj1-node    Running        Running about a minute ago         
ld6w8owhu3ct   \_ proj1_app.1         python:alpine                                          proj1-node    Running        Running about a minute ago         
iiddlrud5d1x  proj1_proxy.1           nginx:alpine                                           proj1-node-3  Running        Running about a minute ago         
xrm2on457y49  proj1_cache-2.1         memcached:1.4-alpine                                   proj1-node-2  Running        Running about a minute ago         
xrm2on457y49   \_ proj1_cache-2.1     memcached:1.4-alpine                                   proj1-node-2  Running        Running about a minute ago         
lwpgkkk6kkdz  proj1_cache.1           memcached:1.4-alpine                                   proj1-node    Running        Running about a minute ago         
lwpgkkk6kkdz   \_ proj1_cache.1       memcached:1.4-alpine                                   proj1-node    Running        Running about a minute ago         
lwpgkkk6kkdz   \_ proj1_cache.1       memcached:1.4-alpine                                   proj1-node    Running        Running about a minute ago         
eeco5rl2e4tk  proj1_app.2             python:alpine                                          proj1-node-2  Running        Running about a minute ago         
eeco5rl2e4tk   \_ proj1_app.2         python:alpine                                          proj1-node-2  Running        Running about a minute ago  

有谁知道输出中的任务层次结构意味着什么? proj1_pubsub.1与两个子项列出的事实是什么意思?

proj1_pubsub.1
\_ proj1_pubsub.1
\_ proj1_pubsub.1

docker documentation没有显示此层次结构信息的示例或解释其含义。

1 个答案:

答案 0 :(得分:0)

"树"显示已替换但仍在节点上可用的任务(容器)。

部署服务时,docker会监视支持该服务的任务,如果任务失败,则会启动一个新任务(容器)来替换旧任务。保留旧容器允许您(例如)检查该容器以调查其失败原因,或查看其日志。

当您更新服务时(例如,更新服务以使用更新版本的图像)也会发生同样的情况,在这种情况下,新容器将使用新映像和旧容器启动停了您可以在以下示例中看到这一点;

docker service create --name redis --replicas=2 redis:3.0.6

docker service ps redis

ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE            ERROR               PORTS
2g423t6ulywl        redis.1             redis:3.0.6         moby                Running             Running 16 seconds ago
8b8yn6opxwaj        redis.2             redis:3.0.6         moby                Running             Running 16 seconds ago

现在,将图片更新为redis:3.0.7;

docker service update --image redis:3.0.7 redis

docker service ps redis

ID                  NAME                IMAGE               NODE                DESIRED STATE       CURRENT STATE                    ERROR               PORTS
7dj4opiw1vel        redis.1             redis:3.0.7         moby                Running             Running less than a second ago
2g423t6ulywl         \_ redis.1         redis:3.0.6         moby                Shutdown            Shutdown 8 seconds ago
x15asetswu67        redis.2             redis:3.0.7                             Ready               Pending less than a second ago
8b8yn6opxwaj         \_ redis.2         redis:3.0.6         moby                Shutdown            Running 42 seconds ago

容器的数量"保持在"可以通过--task-history-limit上的docker swarm update选项进行配置,默认为5(删除旧容器之后)

有关" swarm"的更深入信息服务可以在文档的这一部分https://docs.docker.com/engine/swarm/

中找到