Why tags matter
When you push images to a registry (for example, Amazon ECR), tags determine how images are referenced by deployments and teams. Two complementary tagging patterns are common:latest(or a human-friendly semantic version): convenient for quick testing and ad-hoc deployments, but mutable — each push retagslatest.- Immutable identifier (short commit hash, full digest, or CI build number): provides traceability and safe rollbacks because it points to a specific build artifact.
latest plus the safety of an immutable reference for production and auditability.
Typical CI flow
In this example we use AWS CodeBuild to:- Log into ECR.
- Derive an image tag from the commit hash (fallback to
latest). - Build the image and tag it as both
latestand the commit-hash tag. - Push both tags to ECR and register the ECS task definition.
buildspec.yml:
COMMIT_HASHextracts a short commit ID from the CodeBuild environment variableCODEBUILD_RESOLVED_SOURCE_VERSION.IMAGE_TAGbecomes the short commit hash when available; otherwise, it falls back tolatest.- Two tags are pushed so you can reference images by
latestfor quick tests and by commit-hash for production rollbacks and audits.
latest makes iterative testing easier; the commit-hash tag provides an immutable reference for deployments and rollbacks.
Below is an example ECR view where an image has both a commit-hash tag (e.g., EB7245DB) and the latest tag.

EB7245DB matches the image tag in ECR.

Benefits of tagging with commit hashes
- Traceability: Identify the exact source commit that produced a deployed image.
- Rollbacks: To revert, update the ECS task definition to reference the
REPOSITORY_URI:EB7245DBtag (or whichever commit tag you want) and redeploy. This ensures ECS pulls the image built from that commit. - Auditing: Correlate images in ECR with repository history and CI runs to support compliance and incident investigations.
Quick reference: tag types
Example rollback instructions
To roll back an ECS service to an image tagged with a specific commit:- Edit the task definition to reference the exact image tag, e.g.
123456789012.dkr.ecr.us-east-1.amazonaws.com/myrepo:EB7245DB. - Register the new task definition revision:
aws ecs register-task-definition --cli-input-json file://task-definition.json
- Update the service to use the new task definition revision:
aws ecs update-service --cluster my-cluster --service my-service --task-definition my-task:3
Best practice: Tag each build with both a human-friendly tag (for example,
latest or a semantic version) and an immutable identifier (for example, the short commit hash). Push both tags to your registry so you get the convenience of latest plus the traceability and safety of an immutable tag.Do not rely solely on
latest in production. latest is mutable and can make rollbacks or incident investigations difficult because it does not uniquely identify a build artifact.Links and references
- AWS Elastic Container Registry (ECR): https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html
- Docker image tag best practices: https://docs.docker.com/engine/reference/commandline/tag/
- AWS CodeBuild buildspec reference: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html
- AWS ECS task definitions: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definitions.html