How do I enable automated Docker container and image cleanup in Amazon ECS?

Last updated: 2019-04-19

My Amazon Elastic Compute Cloud (Amazon EC2) instance in Amazon Elastic Container Service (Amazon ECS) ran out of space. In my var/log/messages log file, I receive an error similar to the following: "Insufficient free space: 1120 extents needed, but only 19 available."

How can I resolve this error?

Resolution

If you have version 1.13.0 or greater of the Amazon ECS container agent, then your Docker images and stopped tasks are cleaned up automatically with the ECS_DISABLE_IMAGE_CLEANUP variable. Automated image cleanup isn't available in previous versions of the Amazon ECS container agent.

Important: If you set ECS_DISABLE_IMAGE_CLEANUP to true, then automated image cleanup is disabled on your container instance and your images aren't automatically removed.

For more information on the cleanup workflow, see Automated Task and Image Cleanup. For more information on how to configure your automated task and image cleanup variables, see Tunable Parameters.