docker_prune not working with label

218 views
Skip to first unread message

abin stephen

unread,
Dec 16, 2019, 3:34:56 PM12/16/19
to Ansible Project

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

Felix Fontein

unread,
Dec 16, 2019, 3:54:29 PM12/16/19
to ansible...@googlegroups.com
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),
which is passing it to the docker daemon via the API
(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/)
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

abin stephen

unread,
Dec 16, 2019, 3:59:43 PM12/16/19
to Ansible Project
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



Felix Fontein

unread,
Dec 16, 2019, 4:03:08 PM12/16/19
to ansible...@googlegroups.com
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

abin stephen

unread,
Dec 16, 2019, 4:03:32 PM12/16/19
to Ansible Project
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 ?


On Monday, 16 December 2019 15:54:29 UTC-5, Felix Fontein wrote:

abin stephen

unread,
Dec 16, 2019, 4:15:00 PM12/16/19
to Ansible Project
Its failing with


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

Felix Fontein

unread,
Dec 16, 2019, 4:20:32 PM12/16/19
to ansible...@googlegroups.com
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
--
Felix Fontein -- fe...@fontein.de -- https://felix.fontein.de/

abin stephen

unread,
Dec 16, 2019, 5:46:01 PM12/16/19
to Ansible Project
Is this module available in ansible 2.7.10?

Matt Martz

unread,
Dec 16, 2019, 6:04:54 PM12/16/19
to ansible...@googlegroups.com
No, per the documentation which you can find at https://docs.ansible.com/ansible/latest/modules/docker_prune_module.html

It states: "New in version 2.8."

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5264b9ac-317f-4920-8add-af9f6968df2e%40googlegroups.com.


--
Matt Martz
@sivel
sivel.net
Reply all
Reply to author
Forward
0 new messages