August 3, 2018 · ansible Docker

Ansible - Clean up old Docker images

To keep this blog-thing alive, here comes a short post about cleaning up old Docker images using Ansible.


First of you have to install the docker Python package on your Docker host.

Install with pip like this
pip install docker

or like this if you are using Python3
pip3 install docker

Note: If you have docker-py installed you have to uninstall it before installing the new docker package


- name: Run docker image clean up
  hosts: linux
    - name: Start garbage collector container
        name: docker-gc
        image: spotify/docker-gc
        state: started
        auto_remove: yes
          - /var/run/docker.sock:/var/run/docker.sock
          - /etc:/etc:ro