# Docker cleanup policy based on tags

**URL:** <https://community.sonatype.com/t/docker-cleanup-policy-based-on-tags/8111>\
**Category:** Best Practices\
**Tags:** docker, nexus-repository\
**Created:** [January 24, 2022, 9:17am UTC](https://community.sonatype.com/t/docker-cleanup-policy-based-on-tags/8111 "2022-01-24T09:17:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohammadbagher72moussavi](https://yyz1.discourse-cdn.com/flex047/user_avatar/community.sonatype.com/mohammadbagher72moussavi/32/2139_2.png) [@mohammadbagher72moussavi](https://community.sonatype.com/u/mohammadbagher72moussavi)\
**Post date:** [January 24, 2022, 9:17am UTC](https://community.sonatype.com/t/docker-cleanup-policy-based-on-tags/8111/1 "2022-01-24T09:17:28Z")

</div>

Hi, As I see in creating “cleanup policy”, I only can set “Remove components that were published over N days ago” or “Remove components that haven’t been downloaded in N days”.  
But I need to for example have last 20 tags of every single docker image.  
How can I set this policy?  
Thank you.

---

<div class="post-metadata">

**Author:** ![mmartz](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@mmartz](https://community.sonatype.com/u/mmartz)\
**Post date:** [January 24, 2022, 2:01pm UTC](https://community.sonatype.com/t/docker-cleanup-policy-based-on-tags/8111/2 "2022-01-24T14:01:48Z")

</div>

I’m wondering what you mean when you say the last 20 tags? Are you including the “latest” tag in that count? Right now there is no way to have a cleanup policy to do what you’re looking for. You could probably use the REST API to lookup and remove docker images on a regular basis, but that’s really just a stopgap until it’s available in product.

---

<div class="post-metadata">

**Author:** ![mpiggott](https://avatars.discourse-cdn.com/v4/letter/m/f0a364/32.png) [@mpiggott](https://community.sonatype.com/u/mpiggott)\
**Post date:** [January 24, 2022, 3:12pm UTC](https://community.sonatype.com/t/docker-cleanup-policy-based-on-tags/8111/3 "2022-01-24T15:12:18Z")

</div>

You may want to follow this ticket - [[NEXUS-10821] Restore retain/keep only the last X versions - Sonatype JIRA](https://issues.sonatype.org/browse/NEXUS-10821)
