ECR – Working With AWS ECR to Manage Docker Repositories

Pinterest LinkedIn Tumblr

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

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 \

Pushing to docker repository

aws ecr get-login-password --region us-west-2 | docker login --username AWS --password-stdin

docker build -t runner .

docker tag runner:latest

docker push

I am a Devops Engineer, but I would describe myself as a Tech Enthusiast who is a fan of Open Source, Linux, Automations, Cloud and Virtualization. I love learning and exploring new things so I blog in my free time about Devops related stuff, Linux, Automations and Open Source software. I can also code in Python and Golang.

Write A Comment