Search code examples
dockerdocker-registrydocker-image

Check if a specific layer exists in my private Docker registry


I want to check if a specific layer exists in my private Docker registry. To do that I will check if a blob exists with: HEAD /v2/<name>/blobs/<digest>.

My problem is find the layer digest. I've already tried with layer.DiffID [calculated with DiffID = SHA256hex(uncompressed layer tar data)], but is not work because DiffID is not the layer digest.

Anyone know how to calculate/generate the layer digest?


Solution

  • Layer_Digest is calculated with the sha256sum(compressed_layer) and...

    compressed_layer=gzip.NewWriter(uncompressed_layer).

    To get the compressed layer you need to use the GOlang gzip implementation. Only GOlang gzip returns the compressed layer correctly and with this compressed layer it is already possible to generate the digest that is present in the registry.