When my Amazon Elastic Container Service (Amazon ECS) task starts in my service, it uses an older container image. Also, when I delete the older container image, the task doesn't start and I receive a "CannotPullContainer" error.
Short description
When you deploy a container image on a service, Amazon ECS resolves the container image tag to the container image digest. The digest contains the authoritative metadata for the image, so you won't see any changes to the container image until you deploy the container image again. The digest updates when you redeploy container image on a service.
Resolution
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
Update your Amazon ECS service
To update the image digest, use either the Amazon ECS console or AWS Command Line Interface (AWS CLI) to force a new deployment.
Amazon ECS console
To use the Amazon ECS console, see Updating an Amazon ECS service.
AWS CLI
Run the update-service command:
aws ecs update-service --service SERVICE_NAME --cluster CLUSTER_NAME --force-new-deployment
Note: Replace SERVICE_NAME with your service name, and CLUSTER_NAME with your cluster name.
To always use a specific image, specify the image digest directory in the task definition.
Resolve the "CannotPullContainer" error
If you receive a CannotPullContainer error after you delete an older container image, then redeploy the container image to update the digest.
To use the newest container image that has a specific tag, update the service and resolve the image digest again.
Note: Services that use the CODE_DEPLOY or EXTERNAL deployment controller don't resolve the container image tag.
Turn off version consistency
To turn off version consistency, set versionConsistency to disabled. When you turn off version consistency, Amazon ECS Service pulls newest image for each task.