Skip to content

Instantly share code, notes, and snippets.

@ericmdev
Forked from michaelneale/docker-clean
Created April 22, 2016 06:44
Show Gist options
  • Save ericmdev/dd54b407b8f0aa25d3aa92c6088118c9 to your computer and use it in GitHub Desktop.
Save ericmdev/dd54b407b8f0aa25d3aa92c6088118c9 to your computer and use it in GitHub Desktop.

Revisions

  1. @michaelneale michaelneale revised this gist Jul 28, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion docker-clean
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    remove_dangling() {
    echo "Removing dangling images ..."
    docker images -f dangling=true -q
    docker rmi $(docker images -f dangling=true -q)
    }

    remove_stopped_containers() {
  2. @michaelneale michaelneale revised this gist Jul 28, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion docker-clean
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ case $1 in
    remove_dangling
    ;;
    containers)
    read -p "Are you sure? " -n 1 -r
    read -p "Are you sure you want to remove all stopped containers?" -n 1 -r
    echo #
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
  3. @michaelneale michaelneale created this gist Jul 28, 2014.
    33 changes: 33 additions & 0 deletions docker-clean
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/bin/sh

    remove_dangling() {
    echo "Removing dangling images ..."
    docker images -f dangling=true -q
    }

    remove_stopped_containers() {
    echo "Removing stopped containers ..."
    docker rm $(docker ps -qa)
    }

    case $1 in
    images)
    remove_dangling
    ;;
    containers)
    read -p "Are you sure? " -n 1 -r
    echo #
    if [[ $REPLY =~ ^[Yy]$ ]]
    then
    remove_stopped_containers
    fi

    ;;
    *)
    echo "
    usage: docker-clean containers|images
    containers - removes all stopped containers it can.
    images - removes dangling (un-needed) image layers - images you no longer need
    "
    ;;
    esac