programing

도커 이미지의 sha256 코드는 어디에서 찾을 수 있습니까?

randomtip 2021. 1. 18. 07:56
반응형

도커 이미지의 sha256 코드는 어디에서 찾을 수 있습니까?


다음과 같이 sha256 코드를 사용하여 centos, tomcat, ...의 이미지를 가져오고 싶습니다.

docker pull myimage@sha256:0ecb2ad60

하지만 어디에서나 사용할 sha256 코드를 찾을 수 없습니다.

sha256 코드에 대한 힌트가 있는지 dockerhub 저장소를 확인했지만 찾을 수 없었습니다. 태그로 이미지를 다운로드했습니다.

docker pull tomcat:7-jre8

docker inspect메타 데이터에 sha256 코드가 있는지 확인하기 위해 이미지를 확인 했지만 아무것도 없습니다 (이미지의 sha256 코드를 추가하면 sha256 코드가 변경 될 수 있음).

이미지의 sha256 코드를 직접 계산하고 사용해야합니까?


최신 답변

댓글에서 OhJeez가 제안한 편집.

docker inspect --format='{{index .RepoDigests 0}}' $IMAGE

원래 답변

나는 당신이 또한 이것을 사용할 수 있다고 믿습니다

docker inspect --format='{{.RepoDigests}}' $IMAGE

Docker 1.9에서만 작동하며 이미지가 원래 다이제스트에서 가져온 경우에만 작동합니다. 자세한 내용은 도커 문제 추적기에 있습니다.


당신은 그것을 얻을 수 있습니다 docker images --digests

REPOSITORY          TAG    DIGEST                                                                    IMAGE ID     CREATED        SIZE
docker/ucp-agent    2.1.0  sha256:a428de44a9059f31a59237a5881c2d2cffa93757d99026156e4ea544577ab7f3   583407a61900 3 weeks ago    22.3 MB

방금 본 것 :

이미지를 가져 오면 출력 하단에 sha256 코드가 표시됩니다 (다이제스트 : sha ....).

docker pull tomcat:7-jre8
7-jre8: Pulling from library/tomcat
902b87aaaec9: Already exists 
9a61b6b1315e: Already exists 
...   
4dcef5c50d60: Already exists 
Digest: sha256:c34ce3c1fcc0c7431e1392cc3abd0dfe2192ffea1898d5250f199d3ac8d8720f
Status: Image is up to date for tomcat:7-jre8

이 샤 코드

sha256 : c34ce3c1fcc0c7431e1392cc3abd0dfe2192ffea1898d5250f199d3ac8d8720f

나중에 이미지를 당기는 데 사용할 수 있습니다.

docker pull tomcat @ sha256 : c34ce3c1fcc0c7431e1392cc3abd0dfe2192ffea1898d5250f199d3ac8d8720f

이렇게하면 이미지가 변경되지 않고 프로덕션에 안전하게 사용할 수 있습니다.


이전에 사용되지 않는 Docker Hub API 에서 볼 수있는 Id 필드 여야 합니다.

GET /v1/repositories/foo/bar/images HTTP/1.1
  Host: index.docker.io
  Accept: application/json

Parameters:

namespace – the namespace for the repo
repo_name – the name for the repo

응답 예 :

HTTP/1.1 200
Vary: Accept
Content-Type: application/json

[{"id": "9e89cc6f0bc3c38722009fe6857087b486531f9a779a0c17e3ed29dae8f12c4f",
"checksum": "b486531f9a779a0c17e3ed29dae8f12c4f9e89cc6f0bc3c38722009fe6857087"},
{"id": "ertwetewtwe38722009fe6857087b486531f9a779a0c1dfddgfgsdgdsgds",
"checksum": "34t23f23fc17e3ed29dae8f12c4f9e89cc6f0bsdfgfsdgdsgdsgerwgew"}]

그러나 이것은 새로운 도커 배포판 에서 현재 작동하는 방식 아닙니다 . 문제 628 : "태그 이름으로 이미지 ID 가져 오기" 참조

The /v1/ registry response /repositories/<repo>/tags used to list the image ID along with the tag handle.
/v2/ only seems to give the handle.

It would be useful to get the ID to compare to the ID found locally. The only place I can find the ID is in the v1Compat section of the manifest (which is overkill for the info I want)

The current (mid 2015) answer is:

This property of the V1 API was very computationally expensive for the way images are stored on the backend. Only the tag names are enumerated to avoid a secondary lookup.
In addition, the V2 API does not deal in Image IDs. Rather, it uses digests to identify layers, which can be calculated as property of the layer and are independently verifiable.


In addition to the existing answers, you can use the --digests option while doing docker images to get a list of digests for all the images you have.

docker images --digests

You can add a grep to drill down further

docker images --digests | grep tomcat

As mentioned by @zelphir, using digests is not a good way since it doesn't exist for a local-only image. I assume the image ID sha is the most accurate and consistent across tags/pull/push etc.

docker inspect --format='{{index .Id}}' $IMAGE

Does the trick.


Just issue docker pull tomcat:7-jre8 again and you will get what you want.

ReferenceURL : https://stackoverflow.com/questions/32046334/where-can-i-find-the-sha256-code-of-a-docker-image

반응형