ECR – Working With AWS ECR to Manage Docker Repositories

Amazon Elastic Container Registry (Amazon ECR) is a fully managed container registry that makes it easy to store, manage, share, and deploy your container images and artifacts anywhere.
With AWS ECR, you wont need to host your own docker repository.

Log in

# This will output a docker login command that will add a new user-password pair for your Docker configuration
aws ecr get-login --registry-ids 353059476524 --no-include-email

# Use this instead:
$(aws ecr get-login --registry-ids 353059476524 --no-include-email)

aws ecr get-login-password --region region | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com

Create repo for blog-app

aws ecr create-repository --repository-name blog-app

aws ecr create-repository \
    --repository-name blog-app \
    --image-scanning-configuration scanOnPush=true \
    --region us-east-1

Describe repositories

aws ecr describe-repositories

aws ecr describe-repositories --repository-names blog-app

Describe images

aws ecr describe-images --repository-name blog-app

Add Policy to clean up older tags

aws ecr put-lifecycle-policy --registry-id 353059476524 --repository-name randserver --lifecycle-policy-text '{"rules":[{"rulePriority":10,"description":"Expire old images","selection":{"tagStatus":"any","countType":"imageCountMoreThan","countNumber":800},"action":{"type":"expire"}}]}'

list images

aws ecr list-images --repository-name blog-app

# tagStatus = [UNTAGGED, ANY, TAGGED]
aws ecr list-images --repository-name blog-app --filter "tagStatus=ANY"

aws ecr list-images --repository-name blog-app --filter "tagStatus=ANY" --query 'imageIds[0:100]' --output json

aws ecr list-images --repository-name blog-app --filter "tagStatus=ANY" --query 'imageIds[*]' --output text

Delete images

IMAGES_TO_DELETE=`aws ecr list-images --repository-name requestl --filter "tagStatus=ANY" --query 'imageIds[0:100]' --output json`

echo Images to delete
echo ${IMAGES_TO_DELETE} | jq length

aws ecr batch-delete-image --repository-name requestl --image-ids "${IMAGES_TO_DELETE}" --profile citizix || true

aws ecr describe-repositories --output text | awk '{print $5}' | while read line; do  aws ecr list-images --repository-name $line --filter tagStatus=UNTAGGED --query 'imageIds[*]' --output text | while read imageId; do aws ecr batch-delete-image --repository-name $line --image-ids imageDigest=$imageId; done; done

Delete images

aws ecr batch-delete-image --repository-name $line --image-ids imageDigest=$imageId

aws ecr batch-delete-image \
      --repository-name requestl \
      --image-ids imageTag=latest

Delete repository:

aws ecr delete-repository --repository-name test-app

aws ecr delete-repository \
      --repository-name requestl \
      --force

Pushing to docker repository


aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin 018879709937.dkr.ecr.us-west-2.amazonaws.com

docker build -t runner .

docker tag runner:latest 018879709937.dkr.ecr.us-west-2.amazonaws.com/runner:latest

docker push 018879709937.dkr.ecr.us-west-2.amazonaws.com/runner:latest
Last updated on Oct 14, 2024 11:46 +0300
comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy