Using the Docker "before" Filter to Remove Multiple Images – Code with Dan Blog
CRANK

I recently needed to cleanup a bunch of old Docker images on a VM that I run in Azure. While I could remove each image one by one using the standard docker rmi [IMAGE IDS] command, removing multiple images all at once as a batch was preferable.It turns out that removing a specific range of images is fairly straightforward using the “before” filter. You can do the following to list all images that exist before a particular image:docker images danwahlin/nginx-codelabs -f "before=danwahlin/nginx-codelabs:1.15"Running the command will show all of the images that existed before the danwahlin/nginx-codelabs:1.15 image (basically the older images). Once you run the command and confirm that the correct images are showing, you can remove all of them in a batch using the following command:docker images danwahlin/nginx-codelabs -f "before=danwahlin/nginx-codelabs:1.15" -q xargs docker rmiNote that the -qswitch located toward the end of the command is used to only list the IDs for each image.…

blog.codewithdan.com
Related Topics: Docker Containers