Skip to content

How can I automate the cleanup of Docker containers and images in Amazon ECS?

1 minute read
0

I want to automatically clean up Docker containers and images in Amazon Elastic Container Service (Amazon ECS).

Resolution

The Amazon ECS container agent (for versions 1.13.0 or later) automatically cleans up stopped tasks and Docker images that aren't used by tasks on your container instances. By default, the agent cleans up stopped tasks, Docker images, and containers every three hours.

To change the wait period before the agent removes a container, set the ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION variable. The minimum value is 1 second.

Important: If you set ECS_DISABLE_IMAGE_CLEANUP to true, then the agent turns off automated image cleanup on your container instance and doesn't automatically remove your images.

For more information, see Automatic Amazon ECS task and image cleanup.

Related information

Amazon Elastic Container Service Agent on GitHub

Updating the Amazon ECS container agent

Creating a container image for use on Amazon ECS

AWS OFFICIALUpdated 6 months ago