简体   繁体   English

Docker SDK 与 Google 容器注册表

[英]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:但是,在撰写本文时,以下任何一项都是不可能的:

  • Docker SDK: client.images.list() only lists local images Docker SDK: client.images.list()只列出本地图片
  • there is no Google Client library for GCR GCR 没有 Google 客户端库
  • images are stored in GCS but as one big list of digests with no metadata.图像存储在 GCS 中,但作为一个没有元数据的大摘要列表。 Cannot tell the repo or tags无法告诉 repo 或标签
  • docker registry in desktop is experimental and not available for querying GCR桌面中的docker 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?对于DockerGoogle 员工,是否有计划扩展您的 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.

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