Skip to content

Instantly share code, notes, and snippets.

@ljay79
Created July 2, 2018 08:45
Show Gist options
  • Save ljay79/493712bf5d372631e8b91c56756859a8 to your computer and use it in GitHub Desktop.
Save ljay79/493712bf5d372631e8b91c56756859a8 to your computer and use it in GitHub Desktop.
#! /bin/bash
#
# General docker cleanup. Handy if you've been ahcking and need the
# accumulated juk to be blown away. Use at your own risk.
#
# First, remove the non-running containers.
# docker rm $(docker ps -aq -f "status=exited")
TAINERS=`docker ps -aq -f "status=exited" -f "status=dead"`
if test x"$TAINERS" != x; then
echo -n 'Removing exited containers...'
docker rm $TAINERS
fi
# Next, remove failed images.
# docker rmi $(docker images -q -f "dangling=true")
MAGES=`docker images -q -f "dangling=true"`
if test x"$MAGES" != x; then
echo -n 'Removing dangling images'
docker rmi $MAGES
fi
# docker rmi $(docker images --filter dangling=true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment