# Cron Job to remove dangling docker images

**URL:** https://meta.discourse.org/t/cron-job-to-remove-dangling-docker-images/348208
**Category:** Support
**Created:** [January 21, 2025, 3:53pm UTC](https://meta.discourse.org/t/cron-job-to-remove-dangling-docker-images/348208 "2025-01-21T15:53:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![LotusJeff](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lotusjeff/32/477888_2.png) [@LotusJeff](https://meta.discourse.org/u/LotusJeff)
#### Post date: [January 21, 2025, 3:53pm UTC](https://meta.discourse.org/t/cron-job-to-remove-dangling-docker-images/348208/1 "2025-01-21T15:53:59Z")

</div>

I am looking at setting up the following command as a cron job. The purpose of this command is to remove old containers that are no longer needed by Discourse. It will automatically manage my docker space consumption.

```plaintext
docker images --quiet --filter=dangling=true | xargs --no-run-if-empty docker rmi

```

The filter will only list docker images listed as `<none> <none>`. Then it will delete the images. This is set up to be run silently without human interaction.

As anyone else done this? Any _gotchas_ or _oh crap_ moments I need to be aware of?

or is there a better way?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [January 21, 2025, 3:56pm UTC](https://meta.discourse.org/t/cron-job-to-remove-dangling-docker-images/348208/2 "2025-01-21T15:56:28Z")

</div>

> [@LotusJeff](#):
>
> or is there a better way?

Those files are never generated automatically, so there’s no reason for cron to do it. If you think you want to clean up images, then just do it after every rebuild.

---

<div class="post-metadata">

### Author: ![LotusJeff](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lotusjeff/32/477888_2.png) [@LotusJeff](https://meta.discourse.org/u/LotusJeff)
#### Post date: [January 21, 2025, 4:14pm UTC](https://meta.discourse.org/t/cron-job-to-remove-dangling-docker-images/348208/3 "2025-01-21T16:14:01Z")

</div>

Preferences. I will forget to clean up the files after a rebuild. This way, I don’t have to remember a manual task.
