1

I would like to remove all docker images, which are not labeled with 2 or more labels. Since Ansible 2.8 there is a docker_prune command, which I would like to use in combination with the images_filter options like this:

docker_prune:
  debug: yes
  containers: no
  images: yes
  images_filters:
    label: not label1 label2
    dangling: false

In the docker prune documentation there is an easy way to to that:

docker image prune --filter="label!=label1!=label2"

Is there any way to negate the label option in the command or is the only way to loop over the docker_prune with the help of a label list?

Alucard
  • 317
  • 1
  • 3
  • 15

1 Answers1

-1

Sorry, I wrote that from memory. The command works like this:

$ docker system prune --help

Usage:  docker system prune [OPTIONS]

Remove unused data

Options:
  -a, --all             Remove all unused images not just dangling ones
      --filter filter   Provide filter values (e.g. 'label=<key>=<value>')
  -f, --force           Do not prompt for confirmation
      --volumes         Prune volumes

So, it should have similar options instead:

- name: prune docker
  docker_prune:
    volumes: true
    tagged_images: true
    filters:
    - label!=<key>

The currently supported filters for label:

label (label=<key>, label=<key>=<value>, label!=<key>, or label!=<key>=<value>) - only remove containers, images, networks, and volumes with or ( without, in case label!=... is used) the specified labels.