Docker 服务更新时间戳

Docker Service updatedAt timestamp

Docker Swarm API 客户端具有以下服务元信息:

Meta.UpdatedAt

这是上次用户启动的时间戳 update(例如更改服务配置)还是 任何 服务更改的时间戳,甚至 Docker Swarm 表演?

例如,如果我的 swarm 服务有 5 个任务分布在集群中,然后 Docker 由于某种原因将一个任务从一个节点移动到另一个节点(因此服务配置没有改变);它会更新这个字段吗?

简短回答:不,这不会。

如果您查看源代码,meta.UpdatedAt 是通过 update 调用的 touchMeta 方法更改的。对于服务,处理此问题的方法是 UpdateService,它链接到 docker service update cli 命令。所以从技术上讲,meta.UpdatedAt 仅在您使用 docker service update.

时更新

您可以在本地机器或集群上按照以下场景快速测试:

$ docker service create --name redis --replicas 5 redis

$ docker service inspect --format='{{.Meta.UpdatedAt}}' redis
2017-01-07 15:16:14.910287822 +0000 UTC

$ docker rm -f <some-redis-task-id>

# Swarm should re-schedule the forced removed task onto another node

$ docker service inspect --format='{{.Meta.UpdatedAt}}' redis
2017-01-07 15:16:14.910287822 +0000 UTC

meta.UpdatedAt 字段应保持不变。

现在调用 docker service update redis --replicas 10,您应该会看到新的时间戳。