MCPcopy Index your code
hub / github.com/GoogleCloudPlatform/docker-credential-gcr

github.com/GoogleCloudPlatform/docker-credential-gcr @v2.1.32

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.1.32 ↗ · + Follow
205 symbols 616 edges 29 files 109 documented · 53% 6 cross-repo links updated 4mo agov2.1.32 · 2026-02-18★ 31518 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

docker-credential-gcr Build Status Go Report Card

Introduction

docker-credential-gcr is Google Container Registry's standalone, gcloud SDK-independent Docker credential helper. It allows for v18.03+ Docker clients to easily make authenticated requests to GCR's repositories (gcr.io, eu.gcr.io, etc.).

Note: docker-credential-gcr is primarily intended for users wishing to authenticate with GCR in the absence of gcloud, though they are not mutually exclusive. For normal development setups, users are encouraged to use gcloud auth configure-docker, instead.

The helper implements the Docker Credential Store API, but enables more advanced authentication schemes for GCR's users. In particular, it respects Application Default Credentials and is capable of generating credentials automatically (without an explicit login operation) when running in App Engine or Compute Engine.

For even more authentication options, see GCR's documentation on advanced authentication methods.

Installation

Download latest release.

Install manually:

go install github.com/GoogleCloudPlatform/docker-credential-gcr/v2@latest

Configuration and Usage

  • Configure the Docker CLI to use docker-credential-gcr as a credential helper for the default set of GCR registries:

    shell docker-credential-gcr configure-docker

To speed up docker builds, you can instead configure a minimal set of registries:

shell docker-credential-gcr configure-docker --registries="gcr.io,us-west1-docker.pkg.dev,docker.europe-west3.rep.pkg.dev"

  • Alternatively, use the manual configuration instructions below to configure your version of the Docker client.

  • Log in to GCR (or don't! See the GCR Credentials section)

    shell docker-credential-gcr gcr-login

  • Use Docker!

    shell docker pull gcr.io/project-id/neato-container

  • Log out from GCR

    shell docker-credential-gcr gcr-logout

GCR Credentials

By default, the helper searches for GCR credentials in the following order:

  1. In the helper's private credential store (i.e. those stored via docker-credential-gcr gcr-login)
  2. In a JSON file whose path is specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable.
  3. In a JSON file in a location known to the helper:
    • On Windows, this is %APPDATA%/gcloud/application_default_credentials.json.
    • On other systems, $HOME/.config/gcloud/application_default_credentials.json.
  4. On Google App Engine, it uses the appengine.AccessToken function.
  5. On Google Compute Engine, Kubernetes Engine, and App Engine Managed VMs, it fetches the credentials of the service account associated with the VM from the metadata server (if available).

Users may limit, re-order how the helper searches for GCR credentials using docker-credential-gcr config --token-source. Number 1 above is designated by store and 2-5 by env (which cannot be individually restricted or re-ordered). Multiple sources are separated by commas, and the default is "store, env".

While it is recommended to use gcloud auth configure-docker in gcloud-based work flows, you may optionally configure docker-credential-gcr to use gcloud as a token source (see example below).

Examples:

To use only the gcloud SDK's access token:

docker-credential-gcr config --token-source="gcloud"

To search the environment, followed by the private store:

docker-credential-gcr config --token-source="env, store"

To verify that credentials are being returned for a given registry, e.g. for https://gcr.io:

echo "https://gcr.io" | docker-credential-gcr get

Other Credentials

As of the 2.0 release, docker-credential-gcr no longer supports generalized credsStore functionality.

Manual Docker Client Configuration

Add a credHelpers entry in the Docker config file (usually ~/.docker/config.json on OSX and Linux, %USERPROFILE%\.docker\config.json on Windows) for each GCR registry that you care about. The key should be the domain of the registry (without the "https://") and the value should be the suffix of the credential helper binary (everything after "docker-credential-").

e.g. for `docker-credential-gcr`:
    {
      "auths" : {
            ...
      },
      "credHelpers": {
            "coolregistry.com": ... ,
            "gcr.io": "gcr",
            "asia.gcr.io": "gcr",
            ...
      },
      "HttpHeaders": ...
      "psFormat": ...
      "imagesFormat": ...
      "detachKeys": ...
    }
  

License

Apache 2.0. See LICENSE for more information.

Extension points exported contracts — how you extend this code

GCRCredStore (Interface)
GCRCredStore describes the interface for a store capable of storing both GCR's credentials (OAuth2 access/refresh tokens [3 …
store/store.go
Command (Interface)
Command execs a command with the given arguments. [3 implementers]
util/cmd/exec.go
UserConfig (Interface)
UserConfig describes [3 implementers]
config/file.go

Core symbols most depended-on inside this repo

equal
called by 10
config/file.go
Get
called by 9
credhelper/helper.go
getGCRAccessToken
called by 9
credhelper/helper.go
GetGCRAuth
called by 9
store/store.go
TokenSources
called by 9
config/file.go
helperErr
called by 8
credhelper/helper.go
helperCmd
called by 8
test/util.go
NewMockGCRCredStore
called by 8
mock/mock_store/mocks.go

Shape

Function 102
Method 76
Struct 24
Interface 3

Languages

Go100%

Modules by API surface

store/store.go19 symbols
mock/mock_store/mocks.go18 symbols
config/file.go15 symbols
mock/mock_config/mocks.go14 symbols
store/store_integration_test.go13 symbols
credhelper/helper.go13 symbols
auth/login_integration_test.go13 symbols
credhelper/helper_unit_test.go9 symbols
config/config_file_unit_test.go9 symbols
auth/login.go9 symbols
cli/config.go8 symbols
test/util.go7 symbols

For agents

$ claude mcp add docker-credential-gcr \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact