如何使用gcloud或其他CLI在Google Container Registry中列出已发布的容器图像

是否有gcloud API或其他命令行界面(CLI)访问私有Google容器registry中已发布的容器图像列表? (这是Google云端平台项目中的容器registry)

gcloud container似乎没有帮助:

 $ gcloud container Usage: gcloud container [optional flags] <group | command> group may be clusters | operations command may be get-server-config Deploy and manage clusters of machines for running containers. flags: --zone ZONE, -z ZONE The compute zone (eg us-central1-a) for the cluster global flags: Run `gcloud -h` for a description of flags available to all commands. command groups: clusters Deploy and teardown Google Container Engine clusters. operations Get and list operations for Google Container Engine clusters. commands: get-server-config Get Container Engine server config. 

我也不想使用gcloud docker来列出图像,因为它想连接到我没有的特定的docker守护进程。 除非有办法告诉gcloud docker连接到一个远程的公共gcloud docker守护进程,它可以读取通过我的项目推送到registry的私有容器。

我们刚刚发布了一个新的命令来列出您的存储库中的图像! 你可以尝试一下:

 gcloud alpha container images list --repository=gcr.io/$MYREPOSITORY 

如果你想看到一个图片的特定标签,你可以使用:

 gcloud alpha container images list-tags gcr.io/$MYREPOSITORY/$MYIMAGE 

Robert Bailey给出的答案对于某些任务是有好处的,但是可能会错过你特别想做的事情。 尽pipe如此,你的回答并不是他的回答,而是你自己对“失败”的命令实际上意味着什么的理解。

至于你的第二个评论,

使用docker我得到以下错误(出于上面提到的原因;我也编辑了这个问题): Cannot connect to the Docker daemon. Is the docker daemon running on this host? Cannot connect to the Docker daemon. Is the docker daemon running on this host?

这是docker守护进程没有运行的结果。 检查它是否通过ps aux | grep docker运行 ps aux | grep docker 。 您可以参考Docker文档来确定如何正确安装和运行它。

至于你的第一个评论,

使用curl我得到: {"errors":[{"code":"DENIED","message":"Failed to read tags for repository '<my_project>/<my_image>'"}]} 。 我必须以某种方式进行身份validation才能访问私有registry中的图像。 我不想使用泊坞窗,因为这意味着我必须有一个docker守护程序可用。 我只想看看具有特定版本的容器图像是否在容器registry中。 所以我需要的是在Google Developer Console中的容器registry的API。

正如罗伯特最近的评论中所提到的,除非它是公开的,否则你将无法curl这个形象,或者除非你在curl的调用中提供了一些很好的oauth标题。

您应该使用gcloud docker尝试列出registry中的图像,就像您为其他dockerregistry一样。 gcloud container命令组对于您所需的任务是错误的。 您可以在下面看到gcloud version 96.0.0命令组的gcloud version 96.0.0 (最新的评论)输出:

 $ gcloud docker Usage: docker [OPTIONS] COMMAND [arg...] docker daemon [ --help | ... ] docker [ --help | -v | --version ] A self-sufficient runtime for containers. Options: --config=~/.docker Location of client config files -D, --debug=false Enable debug mode --disable-legacy-registry=false Do not contact legacy registries -H, --host=[] Daemon socket(s) to connect to -h, --help=false Print usage -l, --log-level=info Set the logging level --tls=false Use TLS; implied by --tlsverify --tlscacert=~/.docker/ca.pem Trust certs signed only by this CA --tlscert=~/.docker/cert.pem Path to TLS certificate file --tlskey=~/.docker/key.pem Path to TLS key file --tlsverify=false Use TLS and verify the remote -v, --version=false Print version information and quit Commands: attach Attach to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders between a container and the local filesystem create Create a new container diff Inspect changes on a container's filesystem events Get real time events from the server exec Run a command in a running container export Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on a container or image kill Kill a running container load Load an image from a tar archive or STDIN login Register or log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container network Manage Docker networks pause Pause all processes within a container port List port mappings or a specific mapping for the CONTAINER ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart a container rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save an image(s) to a tar archive search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop a running container tag Tag an image into a repository top Display the running processes of a container unpause Unpause all processes within a container version Show the Docker version information volume Manage Docker volumes wait Block until a container stops, then print its exit code Run 'docker COMMAND --help' for more information on a command. 

您应该使用gcloud docker search gcr.io/project-id来检查存储库中的哪些图像。 gcloud拥有您的凭据,所以只要您在项目中被authentication为合适的用户,就可以与私人registry通话。


最后,作为一个附加资源:云平台文档有一个关于使用Google Container Registry的整篇文章。

如果您知道托pipe图像的项目(例如, google-containers ),您可以列出图像

 gcloud docker search gcr.io/google_containers 

对于单个图像(例如google-containers项目中的pause图像),您可以使用

 curl https://gcr.io/v2/google-containers/pause/tags/list 

我迄今为止的最佳解决scheme是没有可用的本地docker,也无法连接到远程docker(至less仍需要本地docker客户端,而不是本地守护进程),SSH是进入一个Container Cluster实例运行docker并在那里做我的search,并得到我的原始脚本的结果:

 gcloud compute ssh <container_cluster_instance> -C "sudo gcloud docker search ..." 

当然,为了避免所有详细的输出(比如SSH / Terminal欢迎消息),我使用一些参数来静默执行一下:

 gcloud compute ssh --ssh-flag="-q" "$INSTANCE_NAME" -o LogLevel=quiet -C "sudo gcloud docker search ..." 

我刚刚发现了一个更简单的方法来检查特定的图像。 一旦你已经authenticationgcloud ,使用它来生成访问令牌,从您的私人registry读取:

 curl -u "oauth2accesstoken:$(gcloud auth print-access-token)" https://gcr.io/v2/<projectName>/<imageName>/tags/list