google / google/go-containerregistry
Allow overriding the default repository prefix when parsing image references in `pkg/name`
- Dominant language
- Go
- Stars
- 4k
- Forks
- 686
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 26
Description
## Description
The `pkg/name` package currently interprets shorthand image names like "ubuntu" as
"index.docker.io/library/ubuntu:latest", automatically defaulting missing fields to:
- Registry: index.docker.io
- Repository prefix: library
- Tag: latest
While convenient, this behavior cannot currently be customized. It would be useful to support environments where the default repository prefix differs from "library" (e.g., "default" or "base").
## Proposed solution
Add an optional argument or configuration option to let users specify the default repository prefix when parsing references, for example:
```
ref, err := name.ParseReference("ubuntu", name.WithDefaultRepo("default"))
// -> index.docker.io/default/ubuntu:latest
```
or via a package-level configuration:
`name.SetDefaultRepo("default")`
This would maintain backward compatibility (still defaulting to "library") while allowing users to adapt the behavior to custom registries or mirrors.
## Motivation
This feature would help:
- Integrate with registries that use different default namespaces.
- Improve flexibility when working in registry setups.
- Maintain consistency with existing configuration patterns in the package (e.g. WithDefaultRegistry).
## References
[pkg/name](https://pkg.go.dev/github.com/google/go-containerregistry/pkg/name) documentation
Similar defaulting logic in [name.go](https://github.com/google/go-containerregistry/blob/main/pkg/name/name.go)
Contributor guide
Assessment
This issue has not been assessed yet.