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?

  • File copied by Docker seen as a directory
  • How to prevent Dockerfile caching git clone
  • Docker stack “--force-recreate” in swarm mode using compose file
  • Node webservice in Docker with entrypoint fails but works otherwise
  • Apache not running automatically on docker compose up
  • curl: (7) Failed to connect to localhost port 8090: Connection refused
  • Using --add-host or extra_hosts with docker-compose
  • How can i pre-install plugins in jenkins on Windows docker?
  • Docker build seems to not see requirements.txt even though it's in same directory
  • Executing SQL scripts on docker container
  • ElasticSearch on Elastic Beanstalk
  • docker-compose + external container
  • 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.