Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script to clean up docker
#!/bin/bash
GREEN='\x1B[32m'
RED='\x1B[31m'
NOCOL='\x1B[39m'
echo "${GREEN}Removing exited containers${NOCOL}"
docker rm -v $(docker ps --filter status=dead --filter status=exited -aq)
echo "${GREEN}Removing dangling images${NOCOL}"
docker rmi $(docker images -f "dangling=true" -q)
echo "${GREEN}Removing dangling volumes${NOCOL}"
docker volume rm $(docker volume ls -qf dangling=true)
echo "${RED}'requires at least 1 argument(s)' just means there was nothing to clean${NOCOL}"
echo "${GREEN}All Done.${NOCOL}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.