Created
June 2, 2015 16:50
-
-
Save flomotlik/70500fe79d36d509b1cb to your computer and use it in GitHub Desktop.
Docker Cleanup
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
function docker_cleanup { | |
# Find all containers that have exited | |
containers=`docker ps -a -q | xargs` | |
if [[ $containers ]]; then | |
# Remove exited containers | |
docker stop $containers | |
docker rm $containers | |
else | |
echo "No containers to remove" | |
fi | |
# Find all images that are not tagged | |
images=`docker images -a -q -f dangling=true | xargs` | |
if [[ $images ]]; then | |
# Remove untagged images | |
docker rmi $images | |
else | |
echo "No images to remove" | |
fi | |
# Clean all orphaned data volumes | |
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin/docker-cleanup-volumes | |
# List containers and images that remain | |
docker ps -a | |
docker images -a | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment