Last active
December 3, 2019 20:46
-
-
Save lonefreak/504f8eb1f3111c79c16e to your computer and use it in GitHub Desktop.
Cleaning Up Old/Unused/All Docker Containers/Images
This file contains 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
# removing old containers | |
# linux | |
docker ps -a | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm | |
# macosx | |
docker ps -a | grep 'weeks ago' | awk '{print $1}' | xargs -L 10 docker rm | |
# removing all stopped containers | |
# linux | |
docker ps -a | grep 'Exit' | awk '{print $1}' | xargs --no-run-if-empty docker rm | |
# macosx | |
docker ps -a | grep 'Exit' | awk '{print $1}' | xargs -L 10 docker rm | |
# removing orphan tagless/nameless images | |
# won't remove any image other images depend on | |
# will show Error response from daemon: Conflict, wasn't deleted | |
# linux | |
docker images -a | grep '^<none>' | awk '{print $3}' | xargs --no-run-if-empty docker rmi | |
# macosx | |
docker images -a | grep '^<none>' | awk '{print $3}' | xargs -L 10 docker rmi | |
# removing tagged/named images and ALL its children | |
# BE CAREFUL!!! | |
# linux | |
docker images -a | grep -v "^<" | awk '{print $3}' | xargs --no-run-if-empty docker rmi | |
# macosx | |
docker images -a | grep -v "^<" | awk '{print $3}' | xargs -L 10 docker rmi |
Thanks for the tip. =) I'm glad it helped you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you want
ps -a
rather than -aq, otherwise grep has nothing to match, but this was still helpful, thanks