Created
June 2, 2017 16:13
Star
You must be signed in to star a gist
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 | |
echo "Cleaning up after docker..." | |
STOPPED_CONTAINERS=$(sudo docker ps -aq) | |
if [ -n "${STOPPED_CONTAINERS}" ]; then | |
echo "Removing stopped containers..." | |
sudo docker rm ${STOPPED_CONTAINERS} | |
fi | |
DANGLING_IMAGES=$(sudo docker images -aqf dangling=true) | |
if [ -n "${DANGLING_IMAGES}" ]; then | |
echo "Removing Dangling Images..." | |
sudo docker rmi ${DANGLING_IMAGES} | |
fi | |
DANGLING_VOLUMES=$(sudo docker volume ls -qf dangling=true) | |
if [ -n "${DANGLING_VOLUMES}" ]; then | |
echo "Removing Dangling Volumes..." | |
sudo docker volume rm ${DANGLING_VOLUMES} | |
fi | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment