I've been using the the Docker Python API and Boto3 to build images and push them to Amazon ECR. What I've having difficultly determining is how do I determine if an Image I build already exists in ECR? I can use the Boto3 libraries like so:
import boto3
import botocore
client = boto3.client('ecr')
images = client.list_images(repositoryName=repo_name, registryId=repo_id)
This will give me a list of digests, but they're not the Image digests. They're the Docker repository digests (which is a digest of the image + its manifest). So if I build an image locally, I can't use this to check to see if the image already exists with a tag on Amazon ECR.
import docker
client = docker.from_env()
image = client.build(path=docker_dir)
sha256 = image[0].id # <--This Sha sum is for the image, different from repository
Is there anyway to get the actual image digest for images in a given repository without having to pull the image?
I think you could be doing something wrong because I am using a code so similar to yours and I am getting the digest.
session = boto3.Session(profile_name='default')
ecr = boto3.client('ecr')
docker_api = docker.APIClient()
print(session)
response = client.list_images(
repositoryName='repoparent/reponame',
maxResults=5,
filter={
'tagStatus': 'ANY'
}
)
print (response)
I got like response the imagedigest include in the response
Session(region_name='eu-central-1')
{'imageIds': [{'imageDigest': 'sha256:cbb5f28f7a8377207c8f95e3a9fae311fa12f81a22401e053d5c07fd0f87', 'imageTag': 'temp_e2e_1.0.13'}], 'nextToken': 'ukD72mdD/mC8b5xV3susmJzzaTgp3hKwR9nRUWa1yZZ4wYnPpldlCcKdX0uA+hWWOLo3ccyBGxIDoN9FQLPPEHv2DRd1OrIm4ooJdVM1M6sckRwXypd7HXj/SnA9iMm3YBl8HRpVXD/kVWB2VlNFS4aftrQQgtfrPNl6nb/S4zGFrQGQp23fdsY5TsKrWTLOWrdo8HGhWX2ylJ0Qoi19DAOBEN2/JAwMbk2hyquf5NDeA7omjHUMI1pfX5lpO2FPF39DKMZtzdwe24e8RcHa508aukf9CYW6gya6knjWbJfQSrb4lIP4HsTVBqDUuxg5IC9ghqLdXJNCEzWHzwQtuKg0vLdHmM6iftfrVhsgY6rKtZbcXwxlJb3a7FMMdm', 'ResponseMetadata': {'RequestId': 'fb33b587-795d-11e9-a32-17af1b3e4c54', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': 'fb33587-75d-11e9-a3342-17af1b3e4c54', 'content-type': 'application/x-amz-json-1.1', 'content-length': '532'}, 'RetryAttempts': 0}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.