amazon-ecs-agent icon indicating copy to clipboard operation
amazon-ecs-agent copied to clipboard

Image Removal

Open JasonSwindle opened this issue 11 years ago • 32 comments

Howdy,

Currently the ECS-Agent does not remove old, un-used Docker Images. Over time, this could cause issues with space.

JasonSwindle avatar Jun 18 '15 21:06 JasonSwindle

@JasonSwindle if it helps this is what we're using for now https://github.com/meltwater/docker-cleanup. The main problem is you can't schedule containers like this 1:1 with each host, so we've been adding a bunch with docker run but otherwise it works pretty well

EDIT: It does work pretty well but it has a bit of a gotcha, when you restart dockerd it may remove a container or two before they start which is not really ideal

tj avatar Jun 19 '15 21:06 tj

+1 for this feature. Old unused containers should be cleaned up when new one are being used. Previous one should be preserved for rapid rollback.

dgalichet avatar Aug 25 '15 13:08 dgalichet

+1 for image removal

nritholtz avatar Sep 30 '15 19:09 nritholtz

+1

jonnybazookatone avatar Oct 07 '15 18:10 jonnybazookatone

+1 exactly what I wondered about today!

ehenneken avatar Oct 07 '15 18:10 ehenneken

+1, but minor (docker-cleanup and friends are a good workaround)

vad avatar Oct 08 '15 12:10 vad

+1, issue is much more apparent when this is used on smaller instances like the RancherOS AMI with 8gb of space. We tried using tutumcloud/cleanup at first but it ended up breaking something with docker itself. meltwater/docker-cleanup works like a charm

schuylr avatar Oct 22 '15 16:10 schuylr

+1, cleanup should be an option for ecs agent

aldarund avatar Jan 16 '16 20:01 aldarund

+1

nikuph avatar Feb 01 '16 10:02 nikuph

+1

bhiles avatar Feb 16 '16 16:02 bhiles

This Task Definition should help in the clean-up process.

JasonSwindle avatar Feb 16 '16 16:02 JasonSwindle

ecs should upgrade Docker to version 1.10 which doesn't rely on intermediary layers being present. We are seeing every intermediary layer being a dependency and can't delete old images. So a 1GB deployment eventually fills up all 20GB of storage, making deployments impossible Agent version 1.8.1 Docker version 1.9.1

wwallace avatar Mar 04 '16 00:03 wwallace

+1, this is really needed.

ryanwalls avatar Mar 16 '16 04:03 ryanwalls

+1 please, please go for it!

ChrisHubinger avatar Mar 31 '16 15:03 ChrisHubinger

+1 This just bit me in a production environment - ran out of logical volume space and dmeventd went nuts eating loads of CPU for days on end. Manually clearing out old unused images fixed the issue - I need to happen automatically in the agent!\

npahucki avatar Apr 29 '16 15:04 npahucki

spoke with aws support, their suggested approach for now is to have ecs-agent version 1.8.1, add ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION=5m either in /etc/ecs/ecs.config or as a -e option when you run docker run ecs-agent

and then have a crontab job on the host, something like: 0 0 * * * docker images -q | xargs -l --no-run-if-empty docker rmi

which will remove any images not being used by running containers every day at 12am - can set it to every 5m to follow a hyperactive cleanup task if you want.

for reference, ECS_ENGINE_TASK_CLEANUP_WAIT_DURATION - this is a value that specifies how often to clean up "dead" tasks, the default is set to 3 hours and the minimum respected value is 1m, anything less is not possible.

So I didn't bother setting this cos 3 hours default would still mean my stale images wont build up too much from the 24hr cron job.

ashramsey avatar Apr 30 '16 03:04 ashramsey

@ashramsey Here's the detailed blog post regarding the same.

aaithal avatar May 02 '16 15:05 aaithal

The approach @ashramsey suggested is great, thanks for that. :smile:

I only have one complaint... running docker images -q | xargs --no-run-if-empty docker rmi removes all the REPOSITORY and TAG information from my images. Is there a way to prevent that from happening?

Before...

[ec2-user@ip-10-0-16-139 ~]$ docker images
REPOSITORY                     TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
wpsinc/novus-acp-laravel       v154                6a0b28834462        2 hours ago         521.9 MB
wpsinc/novus-api-laravel       v873                c3a30f0e4cfc        24 hours ago        558.9 MB
wpsinc/ad-map-laravel          v34                 2dc593b48671        45 hours ago        519.8 MB
wpsinc/alchemy-laravel         v724                49bf5abfe00e        46 hours ago        552.1 MB
wpsinc/hdtwin-laravel          v100                0e0f0752ed23        47 hours ago        533.6 MB
wpsinc/gmaxhelmet-legacy       v23                 e33f091fc1eb        8 days ago          404.9 MB
wpsinc/subsidiaries-drupal     v200                2cfe5ec45292        10 days ago         647.8 MB
wpsinc/calypso-laravel         v87                 08800bf41a49        10 days ago         526.4 MB
wpsinc/gmaxhelmet-apache-php   latest              5ed9e4e3d425        10 days ago         541.5 MB
wpsinc/hdtwin-php-fpm          latest              3f6db539e3b0        2 weeks ago         518.7 MB

Then I run...

[ec2-user@ip-10-0-16-139 ~]$ docker images -q | xargs --no-run-if-empty docker rmi

This works great and removes any unused images. The problem is the images that are used by running containers have their info stripped from them.

After...

[ec2-user@ip-10-0-16-139 ~]$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>              <none>              6a0b28834462        2 hours ago         521.9 MB
<none>              <none>              c3a30f0e4cfc        24 hours ago        558.9 MB
<none>              <none>              2dc593b48671        45 hours ago        519.8 MB
<none>              <none>              49bf5abfe00e        46 hours ago        552.1 MB
<none>              <none>              0e0f0752ed23        47 hours ago        533.6 MB
<none>              <none>              e33f091fc1eb        8 days ago          404.9 MB
<none>              <none>              2cfe5ec45292        10 days ago         647.8 MB
<none>              <none>              08800bf41a49        10 days ago         526.4 MB
<none>              <none>              5ed9e4e3d425        10 days ago         541.5 MB
<none>              <none>              3f6db539e3b0        2 weeks ago         518.7 MB

Of course, the ideal solution would be if there were ECS settings we could configure to remove old unused Docker images at a specified frequency or certain rules we could set up. :+1:

AustinMaddox avatar May 27 '16 18:05 AustinMaddox

+1

aboutvale avatar Jun 22 '16 18:06 aboutvale

+1

lafraia avatar Jul 01 '16 18:07 lafraia