# docker\_prune not working with label

**URL:** <https://forum.ansible.com/t/docker-prune-not-working-with-label/31830>\
**Category:** Ansible Project\
**Created:** [December 16, 2019, 8:34pm UTC](https://forum.ansible.com/t/docker-prune-not-working-with-label/31830 "2019-12-16T20:34:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![abin\_stephen](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@abin\_stephen](https://forum.ansible.com/u/abin_stephen)\
**Post date:** [December 16, 2019, 8:34pm UTC](https://forum.ansible.com/t/docker-prune-not-working-with-label/31830/1 "2019-12-16T20:34:56Z")

</div>

How we can configure docker\_prune to delete docker images with specific name, I have tried something below and it didt worked can you please help us to fix this

> |
> 
> - |

| |
|
| |

> |
> 
> - |

- name: Remove unused images  
docker\_prune:  
images: yes  
images\_filters:  
label: appName=hello

| |
|
| |

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [December 16, 2019, 8:54pm UTC](https://forum.ansible.com/t/docker-prune-not-working-with-label/31830/2 "2019-12-16T20:54:15Z")

</div>

Hi,

the filters you pass are passed over to docker-py  
([https://docker-py.readthedocs.io/en/stable/api.html#docker.api.image.ImageApiMixin.prune\_images](https://docker-py.readthedocs.io/en/stable/api.html#docker.api.image.ImageApiMixin.prune_images)),  
which is passing it to the docker daemon via the API  
([https://docs.docker.com/engine/api/v1.39/#operation/ImagePrune](https://docs.docker.com/engine/api/v1.39/#operation/ImagePrune)).

The docker-py documentation only mentions the dangling filter, while  
the CLI docs  
([https://docs.docker.com/engine/reference/commandline/image\_prune/](https://docs.docker.com/engine/reference/commandline/image_prune/))  
also mention the label filter you are using.

The task you've posted looks like it \*should\* pass the correct values  
to the docker daemon.

What exactly was the problem? Did you get an error message, or was an  
image simply not deleted? (And does docker CLI behave differently?)

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![abin\_stephen](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@abin\_stephen](https://forum.ansible.com/u/abin_stephen)\
**Post date:** [December 16, 2019, 8:59pm UTC](https://forum.ansible.com/t/docker-prune-not-working-with-label/31830/3 "2019-12-16T20:59:43Z")

</div>

Can you please confirm whether the synatx I am using here is correct?

- name: Remove unused images

docker\_prune:  
images: yes  
images\_filters:

label: appName=hello

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [December 16, 2019, 9:02pm UTC](https://forum.ansible.com/t/docker-prune-not-working-with-label/31830/4 "2019-12-16T21:02:53Z")

</div>

Hi,

> Can you please confirm whether the synatx I am using here is correct?

I think it is correct. I've never tried prune by labels, but from  
looking at the module's code, docker-py's code and docker CLI's code, I  
would expect this to work.

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![abin\_stephen](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@abin\_stephen](https://forum.ansible.com/u/abin_stephen)\
**Post date:** [December 16, 2019, 9:03pm UTC](https://forum.ansible.com/t/docker-prune-not-working-with-label/31830/5 "2019-12-16T21:03:32Z")

</div>

its working in docker CLI \< docker image prune -a --force --filter=“label=appname=helloworld” \>

i want do the same with docker\_prune is it possible ?

---

<div class="post-metadata">

**Author:** ![abin\_stephen](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@abin\_stephen](https://forum.ansible.com/u/abin_stephen)\
**Post date:** [December 16, 2019, 9:15pm UTC](https://forum.ansible.com/t/docker-prune-not-working-with-label/31830/6 "2019-12-16T21:15:00Z")

</div>

Its failing with

```auto
TASK [Run docker_compose_services role] ****************************************
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

The error appears to have been in '/jenkins/workspace/y_real-time-payments_master-WUPVH7HV2NXJH4IGGIT24TMVMKH2JS77LLYJC2NU762UZQBOUNEQ/roles/deploy_docker_compose_services/tasks/main.yml': line 39, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- name: Remove unused images
  ^ here
	to retry, use: --limit @/jenkins/workspace/y_real-time-payments_master-WUPVH7HV2NXJH4IGGIT24TMVMKH2JS77LLYJC2NU762UZQBOUNEQ/deploy_docker_compose_services.retry

```

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [December 16, 2019, 9:20pm UTC](https://forum.ansible.com/t/docker-prune-not-working-with-label/31830/7 "2019-12-16T21:20:19Z")

</div>

Hi,

what you are reporting is not a problem with the module, but a syntax  
error in writing this Ansible task. The way you posted your task to  
this mailing list looked OK, but it appears that the task as used in  
your role has a syntax error.

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![abin\_stephen](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@abin\_stephen](https://forum.ansible.com/u/abin_stephen)\
**Post date:** [December 16, 2019, 10:46pm UTC](https://forum.ansible.com/t/docker-prune-not-working-with-label/31830/8 "2019-12-16T22:46:00Z")

</div>

Is this module available in ansible 2.7.10?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 16, 2019, 11:03pm UTC](https://forum.ansible.com/t/docker-prune-not-working-with-label/31830/9 "2019-12-16T23:03:59Z")

</div>

No, per the documentation which you can find at [https://docs.ansible.com/ansible/latest/modules/docker\_prune\_module.html](https://docs.ansible.com/ansible/latest/modules/docker_prune_module.html)

It states: “New in version 2.8.”
