简体   繁体   中英

Docker SDK with Google Container Registry

We want to query gcr.io using Python. However, as of this writing, any of the below is not possible:

  • Docker SDK: client.images.list() only lists local images
  • there is no Google Client library for GCR
  • images are stored in GCS but as one big list of digests with no metadata. Cannot tell the repo or tags
  • docker registry in desktop is experimental and not available for querying 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.

We could too parse the HTML response from the GCP console (browser) but that would be more work.

Any other idea on how to easily list GCR images in Python?

And to Docker and Googlers , any plan on extending your Python library to interact with remote registries, *.gcr.io in particular?

Google Container Registry implements the same Docker HTTP API as any other Docker registry.

First, get an access token for your account, either with gcloud auth print-access-token or one of these alternatives .

Then, use Docker's"Listing Repositories" endpoint of the HTTP API:

>>> import requests
>>> access_token = ...
>>> resp = requests.get('https://gcr.io/v2/_catalog', auth=('_token', access_token))
>>> resp.json()
{
  "repositories": [
    <name>,
    ...
  ]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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