GoogleContainerTools/skaffold · error

unable to guess GCP projectID from image name [%s]

Error message

unable to guess GCP projectID from image name [%s]

What it means

ExtractProjectID only supports guessing the project ID when the image's registry is gcr.io, a subdomain of gcr.io, or a *-docker.pkg.dev Artifact Registry host, and the name has at least two path components. If neither the parse nor the registry check yields a project, it returns this descriptive error.

Source

Thrown at pkg/skaffold/gcp/projectid.go:42

)

// ExtractProjectID extracts the GCP projectID from a docker image name
// This only works if the imageName is pushed to gcr.io.
func ExtractProjectID(imageName string) (string, error) {
	ref, err := name.ParseReference(imageName, name.WeakValidation)
	if err != nil {
		return "", fmt.Errorf("parsing image name %q: %w", imageName, err)
	}

	registry := ref.Context().Registry.Name()
	if registry == "gcr.io" || strings.HasSuffix(registry, ".gcr.io") || strings.HasSuffix(registry, "-docker.pkg.dev") {
		parts := strings.Split(imageName, "/")
		if len(parts) >= 2 {
			return parts[1], nil
		}
	}

	return "", fmt.Errorf("unable to guess GCP projectID from image name [%s]", imageName)
}

View on GitHub (pinned to a1189de023)

Solutions

  1. Use a fully qualified gcr.io or *-docker.pkg.dev image name containing the project as the first path segment (e.g. gcr.io/my-project/app).
  2. Prepend the project path to local names: 'myimage' -> 'gcr.io/my-project/myimage'.
  3. If the image is not on a Google registry, obtain the project ID from configuration instead of calling ExtractProjectID.
  4. Verify the registry suffix is exactly gcr.io, *.gcr.io, or *-docker.pkg.dev.

Example fix

// before
id, err := gcp.ExtractProjectID("myimage")            // fails
id2, _ := gcp.ExtractProjectID("quay.io/org/img")     // fails
// after
id, err := gcp.ExtractProjectID("gcr.io/my-project/myimage")
Defensive patterns

Strategy: validation

Validate before calling

func canInferProject(imageName string) bool {
    ref, err := name.ParseReference(imageName, name.WeakValidation)
    if err != nil {
        return false
    }
    reg := ref.Context().Registry.Name()
    gcrish := reg == "gcr.io" || strings.HasSuffix(reg, ".gcr.io") || strings.HasSuffix(reg, "-docker.pkg.dev")
    return gcrish && len(strings.Split(imageName, "/")) >= 2
}
// call ExtractProjectID only if canInferProject(imageName)

Try / catch

projectID, err := gcp.ExtractProjectID(imageName)
if err != nil {
    return fmt.Errorf("cannot infer GCP project from %q; supply projectID from config instead", imageName)
}

Prevention

When it happens

Trigger: Calling ExtractProjectID with an image pushed to a non-Google registry (docker.io, quay.io, ghcr.io) or a GCR-style name with fewer than 2 path components (e.g. just 'myimage').

Common situations: Passing a Docker Hub image and expecting a GCP project; local images named without a registry/project prefix; Artifact Registry hosts with unexpected suffixes or custom domains.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/74d636bd951e6e25. Report an issue: GitHub.