Docker old images cleanup?

The output of sudo docker images shows images that were created ages ago, I don’t see any use for them, sudo docker system prune does not remove them either.

How can I easily delete old images? Do I have to write a script to conditionally delete based on date created within the output of docker images?

  • docker build hangs in directory with many files
  • How can I change docker network ip address in Mac
  • Starting bash script on Docker container startup doesn't work
  • Docker getsockopt: connection refuse
  • dockerized HAProxy+Keepalived for HA
  • Docker tomcat editing configuration files through dockerfile
  • Can't connect to MySQL docker container launched via ansible
  • Docker Maven plugin: how to specify shm size when running a container
  • Azure - creating FQDN from a script
  • Node container fails to run using docker for windows
  • Crontab doesn't have credentials
  • Can't connect to ElasticSearch Docker cluster which run on local virtual machine using Java API
  • One Solution collect form web for “Docker old images cleanup?”

    I don’t think you can filter images by created date, but you can use another image as a reference of time.

    The flag (-f or--filter) with before shows only images created before the image with given id or reference.

    For example, having these images:

    $ docker images
    
    REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
    image1              latest              eeae25ada2aa        4 minutes ago        188.3 MB
    image2              latest              dea752e4e117        9 minutes ago        188.3 MB
    image3              latest              511136ea3c5a        25 minutes ago       188.3 MB
    

    Filtering with before (image1) would give:

    $ docker images --filter "before=eeae25ada2aa"
    
    REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
    image2              latest              dea752e4e117        9 minutes ago        188.3 MB
    image3              latest              511136ea3c5a        25 minutes ago       188.3 MB
    

    To Remove images before image1(eeae25ada2aa)

    $ docker rmi $(docker images --filter "since=511136ea3c5a" -q)
    
    dea752e4e117
    511136ea3c5a 
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.