DEV Community

Cover image for How to Re-tag an Image in AWS ECR
Amzar
Amzar

Posted on

How to Re-tag an Image in AWS ECR

Are you managing Docker images in AWS ECR? Sometimes, you need to retag them to keep things organized. In this quick guide, we'll show you how to retag your Docker images in AWS ECR Let'sy. Let’s get started!

Let's consider an image named hello-world-program with the following tags.

current tag new tag
[untagged] 0.0.2

Steps

  1. Setup AWS CLI
  2. Navigate to AWS ECR and choose the images you want to update. Copy the image digest (e.g., sha256:xxx), which is a unique and unchangeable identifier. Each image's content has its own distinct digest.
  3. Open terminal
  4. Run the following command to retrieve the image manifest and store it in the MANIFEST variable:

    MANIFEST=$(aws ecr batch-get-image --repository-name {REPO_NAME} --image-ids imageDigest={IMAGE_DIGEST} --output json | jq --raw-output --join-output '.images[0].imageManifest')
    
  5. Run the following command to update the image:

    aws ecr put-image --repository-name {REPO_NAME} --image-tag {NEW_TAG} --image-manifest "$MANIFEST"
    

Replace {REPO_NAME} with the name of your repository, {IMAGE_DIGEST} with the actual digest you copied from AWS ECR, and {NEW_TAG} with your desired tag

Refresh the page, and you’ll see that the existing [untagged] image is now updated to 0.0.2.

If you're on macOS and encounter the issue jq: command not found, check this guide for help.

Reference

  1. https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-retag.html
  2. https://stackoverflow.com/a/59675086

Top comments (0)