Forked from ngtrieuvi92/remove-unused-docker-images.sh
Created
June 20, 2018 14:27
-
-
Save trankimvu/4927a8b9cd78852f5427063891bc2801 to your computer and use it in GitHub Desktop.
Remove all unused docker image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Remote all exited container | |
docker rm $(docker ps -q -f status=exited) | |
# Remote none tag images (image with tag <none>) | |
docker images | grep "<none>" | awk '{print $3}' |xargs docker rmi -f | |
# Remove all images that is not using by any running container | |
# note: docker ps --format {{.Image} -> List all images of running container then set it as grep pattern | |
docker images --format {{.Repository}}:{{.Tag}} | grep -vFf <(docker ps --format {{.Image}}) | xargs docker rmi -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment