从注册表获取最新的Docker映像创建日期 [英] Get latest Docker image creation date from registry

查看:76
本文介绍了从注册表获取最新的Docker映像创建日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取注册表中存在的Docker映像的最新创建日期?最近,我们遇到了一个问题,即在某些集群从属服务器上,Docker镜像没有被自动拉出,并且该项目在非常陈旧的容器环境中运行。因此,我希望每天运行一次cron脚本,以检查拉出的Docker映像是否比注册表Docker映像早24小时。

How is it possible to get latest creation date of Docker image that exists at registry? Recently we have a problem that Docker image was not automatically pulled at some of our cluster slave servers and the project was running at the very outdated container environment. So am expecting to run a cron-script once per day to check that pulled Docker image is not 24 hours older than registry Docker image.

推荐答案

我知道的最简单的方法是编写一个使用 Docker Registry REST API的简单脚本并根据您的需要对结果进行基本操作。

The simplest way I know of is to write a simple script that uses the Docker Registry REST API and does basic manipulation of the results for your needs.

下面是Python 3中的一些示例代码,可以在我使用的仓库中进行此操作:

Here's some example code in Python 3 that would do this for a repo I work with:

import requests

repo_tag_url = 'https://hub.docker.com/v2/repositories/streamsets/datacollector/tags'
results = requests.get(repo_tag_url).json()['results']
for repo in results:
    print(repo['name'], repo['last_updated'])

例如,返回:

3.0.0.0-SNAPSHOT 2017-10-23T14:43:29.888877Z
latest 2017-10-05T23:05:03.636155Z
2.7.2.0 2017-10-05T22:50:53.269831Z
2.7.2.0-RC5 2017-10-05T19:34:19.523402Z
2.7.2.0-RC4 2017-10-05T02:05:52.522323Z
2.7.2.0-RC3 2017-10-04T00:08:02.929502Z
2.8.0.0-SNAPSHOT 2017-10-03T21:55:08.042479Z
2.7.2.0-RC2 2017-10-03T19:20:56.642686Z
2.7.2.0-RC21 2017-09-30T21:42:27.924190Z
2.7.2.0-RC1 2017-09-30T17:34:14.409320Z

这篇关于从注册表获取最新的Docker映像创建日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆