Skip to content

Instantly share code, notes, and snippets.

@rhblind
Created March 24, 2017 09:06
Show Gist options
  • Save rhblind/0fa655b8e68e8343abac4fb5f2075acb to your computer and use it in GitHub Desktop.
Save rhblind/0fa655b8e68e8343abac4fb5f2075acb to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
EXITED=$(docker ps -q -f status=exited)
DANGLING=$(docker images -q -f "dangling=true")
if [ "$1" == "--dry-run" ]
then
echo "==> Would stop containers:"
echo $EXITED
echo "==> And images:"
echo $DANGLING
else
if [ -n "$EXITED" ]
then
docker rm $EXITED
else
echo "No containers to remove."
fi
if [ -n "$DANGLING" ]
then
docker rmi $DANGLING
else
echo "No images to remove."
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment