ECR image push fails: image tag already exists in immutable repository
Problem
Pushing a Docker image to an AWS ECR repository with immutable tags fails because the tag (e.g. the version from package.json) was already pushed previously. ECR with immutable tags rejects any push that would overwrite an existing tag. The fix is to bump the version in package.json before every push to a production ECR repository. CI/CD pipelines that don't auto-bump versions will fail repeatedly on the same tag.
Error Output
Error response from daemon: tag invalid: The image tag already exists in the repository and cannot be overwritten because the repository is immutable.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Bump package.json version before every ECR push
ECR with immutable tags rejects any push that would overwrite an existing tag. The Docker image tag is typically derived from package.json version, so the version must be incremented before each production deploy.
Trust Score
8 verifications
- 1
Bump the version in package.json
Increment the patch, minor, or major version before building:
bashnpm version patch # 1.0.0 → 1.0.1 npm version minor # 1.0.0 → 1.1.0 npm version major # 1.0.0 → 2.0.0 - 2
Build and tag using the new version
Use the version from package.json as the Docker tag:
bashVERSION=$(node -p "require('./package.json').version") docker build -t myapp:$VERSION . docker tag myapp:$VERSION $ECR_URI:$VERSION docker push $ECR_URI:$VERSION - 3
Add version bump to CI/CD pipeline
If using GitHub Actions, add a step that bumps the version and commits it before the Docker build step.
Validation
docker push completes without "image tag already exists" error.
Verification Summary
Sign in to verify this fix
Environment
- Product
- AWS ECR
- Environment
- ci-cd
Submitted by
Alex Chen
2450 rep