- Newest
- Most votes
- Most comments
This issue is related to how Amazon ECS handles container image resolution. When you deploy a container image on a service, ECS resolves the container image tag to a specific image digest (SHA256), which becomes the authoritative metadata for that image. This digest is cached to maintain consistency within a deployment.
Even though you've updated your image in ECR with the same tag (either 'latest' or a version tag), ECS won't automatically use the new image until the digest is updated. This is why your deployment shows as successful but still runs the old code.
Here are some solutions to ensure ECS uses your updated image:
-
Force a new deployment: You mentioned you did this, but ensure you're using the AWS CLI command
update-service --cluster clustername --service servicename --force-new-deploymentor the equivalent option in the console. -
When you update an image, you must also update the service. By default, ECS resolves container image tags specified in the task definition to container image digests. For a service with multiple tasks, ECS uses the first task started during deployment to establish image digests.
-
Consider using unique tags for each deployment instead of reusing 'latest'. This makes it clearer which version is running and can help avoid caching issues.
-
If you're using a CI/CD pipeline like CodePipeline, ensure it's correctly set up to deploy the right image and that no other pipelines are in progress.
-
Check for any "CannotPullContainerError" in your logs, which might indicate issues with pulling the updated image.
Remember that ECS's behavior of resolving tags to digests is designed to ensure version consistency across your service. By understanding this behavior and implementing appropriate update strategies, you can maintain the flexibility of using tags while ensuring your services use the latest images as intended.
Sources
Use new container image in Amazon ECS | AWS re:Post
Use latest container image digest during Amazon ECS deployments | AWS re:Post
ECS task definition image tag | AWS re:Post
When forcing New deployment with the Service update, ensure the service is pointing to the correct Task Definition! If that is the case, sounds like the Image hasnt been built correctly. You can download the image from ECR and test locally
Relevant content
- asked 7 months ago
- asked 2 years ago
