Docker image search using SHA hash
Asked Answered
M

2

7

I am trying to search for an image using it's SHA256 hash:

I have sha256 hash and I want to know if any docker image with this sha256 hash exists or not. Is it possible to do that and how?

Melesa answered 19/12, 2019 at 6:21 Comment(0)
A
1

You could list all the images with docker images and find a particular one:

docker images --no-trunc -q | grep <image_hash>

Or you want to search via a chunk of hash number:

docker images -q | grep <image_hash>
Alwitt answered 19/12, 2019 at 6:27 Comment(0)
T
0

Here is the easiest way I know using the Docker registry API. If I have an existing Docker repo on the local network, I can query whether a specific image exists there using the SHA hash. Just need to make a simple HTTP GET request. Assemble the string like this -

FullURL = DomainAndPort + "/v2/" + imageName + "/blobs/sha256:" + imageHash;

An example request that works for me on our network repo -
http://10.10.9.84:5000/v2/hello-world/blobs/sha256:8089101ead9ce9b8c68d6859995c98108e1022c23beaa55754acb89d66fd3381

Entering that string into a Chrome browser returns a JSON object describing the image. If you enter an invalid sha256 hash then the API returns -

{"errors":[{"code":"DIGEST_INVALID","message":"provided digest did not match uploaded content","detail":{}}]}

For more details see "Pulling a Layer" in https://docs.docker.com/registry/spec/api/

Thanh answered 21/7, 2021 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.