Ansible Playbooks

Docker - Clean

Welcome

This playbook removes non-dangling Docker images (images that are not being used by any containers) on the specified hosts. It specifically avoids removing stopped containers, unused networks, unused volumes, and builder cache. This helps in cleaning up disk space by removing Docker images that are not in use.

Please be aware, the coding on this site is meant to guide. Testing these scripts in a non-production environment is strongly encouraged. I take no responsibility for use of any scripts on this site or on my github repositories.


Playbook:

---
- name: Clean docker
  hosts: "{{ my_hosts | d([]) }}"

  tasks:
    - name: Prune non-dangling images
      community.docker.docker_prune:
        containers: false
        images: true
        images_filters:
          dangling: false
        networks: false
        volumes: false
        builder_cache: false

View on GitHub