Self-hosted service
google/go-containerregistry avatar
google/go-containerregistry

go-containerregistry: treating container images as immutable values in Go

Go library and CLIs for working with container registries

4,140 stars720 forksGoApache-2.0

At a glance

What is it?
A Go library that models images, layers and indexes as immutable values you can read from and write to any medium, plus crane and its variants as command line tools built on the same primitives.
Who is it for?
go-containerregistry is the right library when your program needs to move or rewrite container images as part of building something else, because a CI step, a Kubernetes operator or a policy engine has no business depending on a Docker daemon. The immutable-view design is what makes it composable: `mutate` returns a new image rather than editing one, and `partial` keeps a custom implementation of the wide `Image` interface manageable.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 4 days ago.
What is it written in?
Mainly Go, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • google/go-containerregistry4,140 ★ · +71
Star history
Repository2026-10-072026-11-22
google/go-containerregistry4.1k4.1k

71 Stars in the last 46 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

Interfaces over media, with a sources and sinks table

The design philosophy in the README is to define interfaces that present an immutable view of a resource, with those interfaces backed by a variety of media. `Image`, `Layer` and `ImageIndex` are the three core types, and behind each one sits any number of implementations depending on where the bytes live.

The README then does something unusually helpful: it lists the sources and sinks for each type as plain reference lists. For `Image`, sources are `remote.Image`, `tarball.Image`, `daemon.Image`, `layout.Image` and `random.Image`, and sinks are `remote.Write`, `tarball.Write`, `daemon.Write`, `legacy/tarball.Write` and `layout.AppendImage`. For `ImageIndex` the sets are smaller, and for `Layer` the sink list is a single entry, `remote.WriteLayer`.

Reading that table is the fastest way to understand the library's scope. `remote` is an HTTP registry, `tarball` is a file on disk, `daemon` is a running Docker daemon, `layout` is an OCI image layout directory, and `random` generates synthetic content for tests. Because they all satisfy the same interface, the choice of medium is a detail of one function call rather than a property of your program.

The `Image` interface is wide, and the README does not hide that. It exposes a lot of derived information, which is by design so the information can be retrieved as efficiently as possible. It is also why the `partial` package exists, which the README describes as somewhat by design and a pain to implement yourself.

Three operations, expressed as source to sink pairs

The simplest thing you can do with these libraries is read from one source and write to another, and the README names three real commands in exactly that form:

bash
crane pull
crane push
crane cp

`crane pull` is a remote image turned into a tarball on disk. `crane push` is the reverse, a tarball written back to a remote registry. `crane cp` is a remote image copied to another remote registry. Each one is a single line of configuration rather than a sequence of steps, because the mutation involved is identity.

The interesting case is when you do want to change something, which is what the `mutate` package is for. It exposes the changes that come up often: setting an entrypoint or a command, replacing an environment variable, adding or removing a layer, editing labels and annotations, appending a config. Since `mutate` follows the same immutable pattern, each operation returns a new image rather than altering the one you passed in, and the README is explicit that the goal is a set of primitives that compose into powerful things.

The README also notes that both views and mutations may be lazy, eager or memoizing, and that most are optimized for the common paths seen in real tooling. That is a design choice worth knowing about. A lazily evaluated layer means you can build a pipeline of mutations and only pay for the bytes you actually need, which is what makes a multi-architecture rewrite feasible in memory terms. The cost is that some mistakes surface at read time rather than at write time.

crane, gcrane, krane and the k8schain fallback

Four command line tools live in the repository, and the differences between them are the reason to understand the family rather than just crane.

`crane` is the general tool for interacting with remote images and registries, documented in `cmd/crane/README.md`. `gcrane` is a GCR-specific variant with richer output for the `ls` subcommand and some basic garbage collection support. That is a narrow tool by design: it exists because garbage collection against Google Container Registry needs registry-specific knowledge that a generic client should not carry.

`krane` is the one to notice. It is a drop-in replacement for crane that supports Kubernetes-based workload identity mechanisms, using `k8schain` as a fallback to traditional authentication. In practice that means it can pick up the identity a kubelet would use, so a CI job running inside a cluster authenticates to the registry without a stored credential. `k8schain` itself is not a tool but a package under `pkg/authn/k8schain` that implements kubelet authentication semantics, and the README links it here for visibility rather than as a command.

That leads to the escape hatch the README provides for people who do not want these abstractions at all. If your goal is to authenticate and send requests to a registry with no image semantics involved, `transport` under `pkg/v1/remote/transport` and `authn` under `pkg/authn` are the packages for you. Using them skips the resource model entirely.

One bit of history worth recording: `ko` was originally developed in this repository and has since moved to its own. If you came for `ko`, it is now at `github.com/google/ko`.

Security fixes in the recent release notes

The recent release history says something about how the project is maintained, and two entries stand out.

In `v0.22.1`, published 2026-09-04, the top change is rejecting non-canonical IP literals in all SSRF guards. That is a real security fix: a registry client that will fetch an image from a URL should not accept a representation of an address that bypasses the guard, and tightening the check in all of them at once means the guards were in more than one place. The same release adds support for pulling images by sha512 digest, and stops `authn` overwriting `AuthConfig.Auth` when both username and password are empty, which would otherwise clobber a credential that was resolved from another source.

`v0.21.9` from 2026-08-05 has a concurrency fix that is worth reading twice: preventing a data race on scope refreshes within `remote.writer`. Registry tokens carry a scope, and a refresh happening while another goroutine reads the scope is exactly the kind of bug that shows up as an intermittent push failure. The same release removes `.` from unsafe path prefixes, which is a path traversal hardening in tar handling.

`v0.22.0` from 2026-08-25 covers the feature side, including allowing single-character repository paths, letting `Time` and `Canonical` take tarball layer options, and resolving push-check credentials against the repository. The presence of dependabot bump entries alongside feature work is a sign the dependency surface is watched rather than neglected.

The last push was on 2026-09-23, and the tree includes `SECURITY.md`, a `.golangci.yaml` for linting and a `.goreleaser.yml` for release automation. The license is Apache 2.0.

Dependencies, toolchain and the shape of a vendored release

`go.mod` is unusually informative because it carries comments explaining itself. The `go` directive is 1.26.0 with a `toolchain` line of go1.26.6, and the comment above it explains the policy directly: do not change the minimum version unless support for older Go versions is dropped or the module needs newer features, and update the toolchain directive for CI and releases.

That is worth pausing on, because requiring a recent Go is a real adoption constraint. If your build environment is on an older release, this module will not compile for you without raising it.

The direct dependencies tell you what the library is built on: `moby/moby/client` and `moby/moby/api` for talking to a daemon, `moby/docker-image-spec` and `opencontainers/image-spec` for the image formats, `opencontainers/go-digest` for content addressing, `klauspost/compress` for compression, `docker/cli` for reference parsing, `cobra` for the command line tools, `spf13/pflag` and `golang.org/x/oauth2` alongside it. The long indirect list includes `docker-credential-helpers`, `containerd/errdefs`, `opencontainers/auto/sdk`, `go-logr` and `logrus`, which tells you the daemon path in particular is not dependency-light.

The tree has a `vendor/` directory, which changes what importing this looks like in practice. `go.mod` also pulls in `google/go-cmp v0.7.0` for tests, the same comparison library that gnostic depends on, which is a small sign of how much of the Go tooling ecosystem agrees on how to compare values.

The library is also the base of Google's `ko`, which builds and pushes container images from Go source. That relationship is the clearest evidence of its maturity: a widely used tool chose this as its foundation rather than shelling out to the Docker CLI.

Where it sits against the Docker CLI and skopeo

The comparison people reach for first is the Docker CLI, and the difference is architectural rather than incremental. `docker` is a client for a daemon, or increasingly a thin shim over containerd, and its commands carry an opinionated model of images, tags and builds. go-containerregistry talks HTTP to the registry directly, so there is no daemon in the path, no privileged socket and no background process. For a CI job running in a container with no Docker access, that is the difference between working and not working.

Against skopeo, the difference is language and shape rather than capability. Both do the same job of copying images between registries and local storage without a daemon. Skopeo is a standalone tool in its own right, and appears in search results alongside this project because people are looking for exactly that capability. If you need the operation once from a shell script, skopeo is a smaller answer. If you need the operation inside a Go program, composing several transformations, calling it a library beats wrapping a binary.

The library's real niche is the third option: CI and GitOps tooling that treats image transformation as a build step. Adding a layer, swapping an architecture, stamping a label, or verifying a signature against an index are all compositions of the primitives in this repository, and expressing them as Go code rather than shell pipelines is the point of the immutable design.

The honest limitation is that the interfaces are wide. `Image` carries enough surface that a hand-rolled implementation is real work, which the README admits, and which is exactly the gap `partial` fills by deriving the accessors from a minimal subset. The second limitation is that `random.Image` and `random.Layer` exist for tests, and the library's optimizations target the paths its authors saw in the wild, so an unusual access pattern may not be the fast one.

Editorial conclusion

go-containerregistry is the right library when your program needs to move or rewrite container images as part of building something else, because a CI step, a Kubernetes operator or a policy engine has no business depending on a Docker daemon. The immutable-view design is what makes it composable: `mutate` returns a new image rather than editing one, and `partial` keeps a custom implementation of the wide `Image` interface manageable. What you give up is any opinion about how images should be laid out, and the interfaces are wide enough that implementing one from scratch is work the `partial` package exists to reduce. Start with `crane` on the command line to see what the operations do, then read `pkg/v1/remote/README.md` before writing code against `pkg/v1`.

Frequently asked questions

What is go-containerregistry?

It is a Go library for working with container registries, and it is largely based on a Python library of the same name. It defines immutable interfaces for images, layers and image indexes, each backed by a different medium such as a remote registry, a tarball, a Docker daemon or an OCI layout.

What is crane and how does it relate to the library?

crane is a command line tool for interacting with remote images and registries, built on the library and documented in the repository under cmd/crane. The README describes crane pull as a remote image written to a tarball, crane push as the reverse, and crane cp as a remote to remote copy.

How do I authenticate to a registry from a Kubernetes workload?

Use krane, a drop-in replacement for crane that supports Kubernetes-based workload identity mechanisms, with the k8schain package as a fallback to traditional authentication. k8schain implements the authentication semantics used by kubelets and lives under pkg/authn/k8schain.

Do I need a Docker daemon to use go-containerregistry?

No. The remote backend talks to a registry over HTTP directly, and tarball and layout backends work on files on disk. The daemon package exists if you want that specific medium, but nothing in the core design requires one.

Official sources

  1. google/go-containerregistry on GitHub
  2. Issues
  3. License: Apache-2.0
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/google-go-containerregistry.svg)](https://hysenlabs.com/projects/google-go-containerregistry)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/google-go-containerregistry.svg)](https://hysenlabs.com/projects/google-go-containerregistry)

Was this useful?