Skip to content

Support SHA256 digest lookup in local image cache#11585

Open
konstantinosGkilas wants to merge 3 commits intotestcontainers:mainfrom
konstantinosGkilas:feature/1406-cache-sha256-digests
Open

Support SHA256 digest lookup in local image cache#11585
konstantinosGkilas wants to merge 3 commits intotestcontainers:mainfrom
konstantinosGkilas:feature/1406-cache-sha256-digests

Conversation

@konstantinosGkilas
Copy link
Copy Markdown

@konstantinosGkilas konstantinosGkilas commented Mar 28, 2026

Summary

  • Index images by their repoDigests in addition to repoTags when populating LocalImagesCache
  • Digest-based image references (e.g. alpine@sha256:...) now resolve from cache without requiring an extra inspectImageCmd call
  • Gracefully skip unparseable digests with a debug log

Problem

LocalImagesCache.populateFromList() only indexed images by repoTags. When users referenced images by SHA256 digest, the cache lookup missed, forcing a redundant inspectImageCmd call on every run.

Changes

  • LocalImagesCache.java: populateFromList() now processes both image.getRepoTags() and image.getRepoDigests(), adding cache entries for each
  • LocalImagesCacheTest.java: New test class covering tag-only, digest-only, mixed, duplicate, and null scenarios

Note

Bare image IDs (sha256:... without a repository prefix) are not indexed because DockerImageName does not support that format. This could be addressed separately if needed.

Test plan

  • LocalImagesCacheTest — 7 unit tests covering all cache population paths
  • checkstyleMain / checkstyleTest / spotlessCheck pass
  • CI passes

Closes #1406

Index images by their repoDigests in addition to repoTags when
populating LocalImagesCache so that digest-based image references
(e.g. alpine@sha256:...) resolve from cache without requiring an
extra inspectImageCmd call.

Closes testcontainers#1406
Copy link
Copy Markdown

@yunhwane yunhwane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work on this! The repoDigests support looks solid and clean.

One thing I noticed — the original issue (#1406) also mentions supporting bare Image IDs (edited by @rnorth on 5 June 2020):

EDIT 5 June 2020: We should also ensure that Image IDs are loaded into the cache - see #699.

The use case is when users reference images by their ID (e.g. from docker build --iidfile):

new GenericContainer<>("sha256:8cf620617c6203b24af7c5bf15a7212386c27ad008fc4c6ff7e37a1bf0a3cdd2")

Currently DockerImageName parses this as repository="sha256", tag="8cf620617c...", which produces a canonical name of sha256:8cf620617c... — so it would match correctly if indexed.

Adding something like this to populateFromList() would cover it:

String id = image.getId();
if (id != null) {
    cache.put(new DockerImageName(id), imageData);
}

Would you be open to adding Image ID indexing as well? That way this PR fully addresses both #1406 and #699.

@konstantinosGkilas
Copy link
Copy Markdown
Author

Nice work on this! The repoDigests support looks solid and clean.

One thing I noticed — the original issue (#1406) also mentions supporting bare Image IDs (edited by @rnorth on 5 June 2020):

EDIT 5 June 2020: We should also ensure that Image IDs are loaded into the cache - see #699.

The use case is when users reference images by their ID (e.g. from docker build --iidfile):

new GenericContainer<>("sha256:8cf620617c6203b24af7c5bf15a7212386c27ad008fc4c6ff7e37a1bf0a3cdd2")

Currently DockerImageName parses this as repository="sha256", tag="8cf620617c...", which produces a canonical name of sha256:8cf620617c... — so it would match correctly if indexed.

Adding something like this to populateFromList() would cover it:

String id = image.getId();
if (id != null) {
    cache.put(new DockerImageName(id), imageData);
}

Would you be open to adding Image ID indexing as well? That way this PR fully addresses both #1406 and #699.

Yes I would implement the needed changes in order to resolve both issues.

@konstantinosGkilas
Copy link
Copy Markdown
Author

@yunhwane Could I have an update on the new changes, that I have introduced?

@yunhwane
Copy link
Copy Markdown

yunhwane commented Apr 3, 2026

Hi, I think you may have tagged the wrong person — I'm not a maintainer or reviewer on this project. I was working on the same issue and noticed our work overlapped. The changes look nice though, good luck with the PR!

@konstantinosGkilas
Copy link
Copy Markdown
Author

Hi, I think you may have tagged the wrong person — I'm not a maintainer or reviewer on this project. I was working on the same issue and noticed our work overlapped. The changes look nice though, good luck with the PR!

Good to know, for some strange reason GitHub has assigned you as a reviewer of the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image cache lookup should support SHA256 digests and Image IDs

2 participants