Skip to content

Instantly share code, notes, and snippets.

@BenjamenMeyer
Created June 2, 2017 16:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save BenjamenMeyer/6e99136d710a8912070f714da625508c to your computer and use it in GitHub Desktop.
docker cleanup
#!/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