[英]Docker SDK with Google Container Registry
We want to query gcr.io
using Python.我们想使用 Python 查询
gcr.io
。 However, as of this writing, any of the below is not possible:但是,在撰写本文时,以下任何一项都是不可能的:
client.images.list()
only lists local images client.images.list()
只列出本地图片docker registry
in desktop is experimental and not available for querying GCRdocker registry
是实验性的,不可用于查询 GCR The only "hack" is to execute gcloud container images list (and list-tags) xxx
in a subprocess and parse to extract the info you need.唯一的“hack”是在子进程中执行
gcloud container images list (and list-tags) xxx
并解析以提取您需要的信息。
We could too parse the HTML response from the GCP console (browser) but that would be more work.我们也可以解析来自 GCP 控制台(浏览器)的 HTML 响应,但这会更有效。
Any other idea on how to easily list GCR images in Python?关于如何在 Python 中轻松列出 GCR 图像的任何其他想法?
And to Docker and Googlers , any plan on extending your Python library to interact with remote registries, *.gcr.io
in particular?对于Docker和Google 员工,是否有计划扩展您的 Python 库以与远程注册表交互,特别是
*.gcr.io
?
Google Container Registry implements the same Docker HTTP API as any other Docker registry. Google Container Registry 与任何其他 ZC5FD214CDD0D2B23B4272E73B0 注册表实现相同的 Docker HTTP API 。
First, get an access token for your account, either with gcloud auth print-access-token
or one of these alternatives .首先,使用
gcloud auth print-access-token
或这些替代方法之一为您的帐户获取访问令牌。
Then, use Docker's"Listing Repositories" endpoint of the HTTP API:然后,使用 HTTP API 的 Docker 的“Listing Repositories”端点:
>>> import requests
>>> access_token = ...
>>> resp = requests.get('https://gcr.io/v2/_catalog', auth=('_token', access_token))
>>> resp.json()
{
"repositories": [
<name>,
...
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.