Following script could help remove all of the docker images starting with a specific prefix. Save the script in a file namely, rmImages.sh. Change the permission using the command such as “chmod u+x rmImages.sh”. Execute the script using the command such as ./rmImages.sh. And, that is it. it would help you delete all the images starting with a specific prefix.
function removeUnwantedImages() {
DOCKER_IMAGE_IDS=$(sudo docker images | grep "$imagePrefix" | awk '{print $3}')
if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" == " " ]; then
echo "---- No images available for deletion ----"
else
sudo docker rmi -f $DOCKER_IMAGE_IDS
fi
}
read -p "Delete images whose prefix is: " imagePrefix
removeUnwantedImages
Latest posts by Ajitesh Kumar (see all)
- Coefficient of Variation in Regression Modelling: Example - November 9, 2025
- Chunking Strategies for RAG with Examples - November 2, 2025
- RAG Pipeline: 6 Steps for Creating Naive RAG App - November 1, 2025
I found it very helpful. However the differences are not too understandable for me