go-containerregistry package lists GCR repositories from all projects / organizations


I am using the following code to list my docker repositories that are available in GCR

package main

import (

    gcr "github.com/google/go-containerregistry/pkg/name"

func main() {

    auth, err := google.NewGcloudAuthenticator()
    if err != nil {
    registry, err := gcr.NewRegistry("gcr.io")
    if err != nil {
    ctx := context.Background()
    repos, err := remote.Catalog(ctx, registry, remote.WithAuthFromKeychain(authn.DefaultKeychain))
    if err != nil {
    for _, repoName := range repos {

The problem is that despite the fact that I have performed an explicit gcloud config set project to a specific project, invocation of the above program will list ALL repos of ALL organizations and ALL projects my gcloud has access to.

Is there a way to limit the code above so that it lists the gcr repos of a specific org/project?


Please note that gcloud config set project only applies to gcloud (CLI) commands but not SDKs.

Seems like this SDK only implements the Docker API, which does not understand the concept of projects. The suggestion here is to migrate to Artifact Registry. You could easily get a list of the repos of a particular project using the list method of the REST Resource projects.locations.repositories. Here you can find an HTTP GET example:

GET /v1beta2/{parent=projects/*/locations/*}/repositories

This answer was created and edited to make the solution given in the comments more visible to the community.

Answered By – Nestor Daniel Ortega Perez

Answer Checked By – Robin (GoLangFix Admin)

Leave a Reply

Your email address will not be published.