Search code examples
amazon-web-servicesamazon-ecs

how long does ECS cache local images?


I have a really big image which takes a long time to pull

When I start a task on an instance it takes like 15+ mins (i have 2 instances). When I start the task again it takes like 2 mins- because the instance has all the layers.

I would Think ECS just keeps the image cached, but if I wait a day or two and run the task again (same image and tag, no new layers) it takes 15mins again.

Is ECS clearing the cache on instances? I only have two instances and confirmed the instances were not deleted/recreated.


Solution

  • It depends on what ECS_IMAGE_PULL_BEHAVIOR is set to. By default, it will pull from remote and use cache only if pull fails.

    You would want to set it as prefer-cached. This will also prevent image cache from being removed by automated image cleanup. Here's the AWS documentation on this - https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-config.html#image_pull