Created
February 12, 2017 22:33
-
-
Save ampedandwired/d3025a4b6f66bdebbd027b7014210d74 to your computer and use it in GitHub Desktop.
Docker cleanup
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
#!/bin/bash | |
# Remove exited containers | |
docker rm $(docker ps -qa --no-trunc --filter "status=exited") | |
# Remove dangling containers | |
docker rmi $(docker images --filter "dangling=true" -q --no-trunc) | |
# Remove unused images (https://github.com/docker/docker/issues/9054#issuecomment-184246090) | |
docker rmi $(grep -xvf <(docker ps -a --format '{{.Image}}') <(docker images | tail -n +2 | grep -v '<none>' | awk '{ print $1":"$2 }')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment