Skip to content

Instantly share code, notes, and snippets.

@mycargus
Last active December 15, 2020 18:22
Show Gist options
  • Save mycargus/cadbf28c9c6f6c5b1f47b6b016a6baa6 to your computer and use it in GitHub Desktop.
Save mycargus/cadbf28c9c6f6c5b1f47b6b016a6baa6 to your computer and use it in GitHub Desktop.

Revisions

  1. mycargus revised this gist Dec 15, 2020. 1 changed file with 32 additions and 22 deletions.
    54 changes: 32 additions & 22 deletions .bashrc
    Original file line number Diff line number Diff line change
    @@ -2,47 +2,57 @@
    # Purpose: reset docker environment
    # Argument (optional): all
    #
    # "docker-reset" will kill and remove all containers (except dinghy_http_proxy),
    # "docker-reset" will kill and remove all containers (except dinghy-http-proxy),
    # dangling images, and volumes. It won't remove networks.
    #
    # "docker-reset all" will do everything in 'docker-reset' and remove all
    # networks, too.
    #
    # Prerequisite: you'll need to install docker-clean: brew install docker-clean
    function docker-reset() {
    run_all=$1

    if [[ "${run_all}" == "all" ]]; then
    docker-kill-all
    echo "Running docker-clean ..."
    docker-clean --containers --images --volumes --networks --log
    else
    docker-kill-all
    echo "Running docker-clean ..."
    docker-clean --containers --images --volumes --log
    fi
    }
    #
    # To use dinghy-http-proxy with docker for mac, follow these instructions:
    # https://github.com/codekitchen/dinghy-http-proxy#using-outside-of-dinghy

    # Purpose: Kill and remove all docker containers (except for dinghy_http_proxy)
    function docker-kill-all() {
    PROXY=$(docker ps | grep dinghy_http_proxy | awk '{print $1}')
    # Kill and remove all docker containers (except for dinghy-http-proxy)
    function docker-kill-all-except-dinghy-http-proxy() {
    PROXY=$(docker ps | grep dinghy-http-proxy | awk '{print $1}')
    echo "Killing docker containers..."
    docker kill $(docker ps -q | grep -v $PROXY) &> /dev/null
    echo "Removing docker containers..."
    docker rm $(docker ps -a --filter "status=exited" -q) &> /dev/null
    }

    # Purpose: Stop and remove all docker containers (except for dinghy_http_proxy)
    function docker-stop-all() {
    PROXY=$(docker ps | grep dinghy_http_proxy | awk '{print $1}')
    # Kill and remove all docker containers
    function docker-kill-all() {
    echo "Killing and removing docker containers..."
    docker rm -fv $(docker ps -a -q) &> /dev/null
    }

    # Stop and remove all docker containers (except for dinghy-http-proxy)
    function docker-stop-all-except-dinghy-http-proxy() {
    PROXY=$(docker ps | grep dinghy-http-proxy | awk '{print $1}')
    echo "Stopping docker containers..."
    docker stop $(docker ps -q | grep -v $PROXY) &> /dev/null
    echo "Removing docker containers..."
    docker rm $(docker ps -a --filter "status=exited" -q) &> /dev/null
    }

    # Purpose: Delete all images related to the provided tag name
    # Example: `docker-nuke selenium` will delete all images whose tags contain the word "selenium"
    function docker-reset() {
    run_all=$1

    if [[ "${run_all}" == "all" ]]; then
    docker-kill-all-except-dinghy-http-proxy
    echo "Running docker-clean ..."
    docker-clean --containers --images --volumes --networks --log
    else
    docker-kill-all-except-dinghy-http-proxy
    echo "Running docker-clean ..."
    docker-clean --containers --images --volumes --log
    fi
    }

    # Purpose: Delete all containers and images related to the provided tag name
    # Example: `docker-nuke selenium node` will delete all containers and images related to "selenium" and "node"
    function docker-nuke() {
    args=("$@")
    docker ps -a | grep ${args[0]} | cut -d ' ' -f 1 | while read ID; do docker rm $ID; done;
  2. mycargus revised this gist Dec 15, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion .bashrc
    Original file line number Diff line number Diff line change
    @@ -58,5 +58,5 @@ function docker-rmi-all() {
    # Example: Using virtualbox as the VM for dinghy's docker host sometimes causes image download
    # latency. Run this function in a separate shell window when that happens.
    function slap-virtualbox() {
    while true; do dinghy ssh echo "turbo mode activated"; done
    while true; do dinghy ssh echo "ಠ_ಠ slap"; done
    }
  3. mycargus revised this gist Mar 7, 2019. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions .bashrc
    Original file line number Diff line number Diff line change
    @@ -15,11 +15,11 @@ function docker-reset() {
    if [[ "${run_all}" == "all" ]]; then
    docker-kill-all
    echo "Running docker-clean ..."
    docker-clean --containers --images --volumes --log
    else
    docker-stop-all
    echo "Running docker-clean --networks ..."
    docker-clean --containers --images --volumes --networks --log
    else
    docker-kill-all
    echo "Running docker-clean ..."
    docker-clean --containers --images --volumes --log
    fi
    }

  4. mycargus revised this gist Mar 7, 2019. 1 changed file with 9 additions and 7 deletions.
    16 changes: 9 additions & 7 deletions .bashrc
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,25 @@

    # Purpose: reset docker environment
    # Argument (optional): all
    # Purpose: reset docker environment
    # Argument (optional): all
    #
    # "docker-reset" will stop and remove all containers (except dinghy_http_proxy) and custom networks
    # "docker-reset" will kill and remove all containers (except dinghy_http_proxy),
    # dangling images, and volumes. It won't remove networks.
    #
    # "docker-reset all" will reset the docker environment to clean slate (you will lose *all* volumes and custom networks!)
    # "docker-reset all" will do everything in 'docker-reset' and remove all
    # networks, too.
    #
    # Note: you'll need to install docker-clean: brew install docker-clean
    # Prerequisite: you'll need to install docker-clean: brew install docker-clean
    function docker-reset() {
    run_all=$1

    if [[ "${run_all}" == "all" ]]; then
    docker-kill-all
    echo "Running docker-clean ..."
    docker-clean
    docker-clean --containers --images --volumes --log
    else
    docker-stop-all
    echo "Running docker-clean --networks ..."
    docker-clean --networks
    docker-clean --containers --images --volumes --networks --log
    fi
    }

  5. mycargus revised this gist May 7, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion .bashrc
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    function docker-reset() {
    run_all=$1

    if [[ "${run_all} == "all" ]]; then
    if [[ "${run_all}" == "all" ]]; then
    docker-kill-all
    echo "Running docker-clean ..."
    docker-clean
  6. mycargus revised this gist May 7, 2018. 1 changed file with 27 additions and 4 deletions.
    31 changes: 27 additions & 4 deletions .bashrc
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,24 @@

    # Purpose: reset docker environment to clean slate (you will lose *all* volumes and custom networks!)
    # Purpose: reset docker environment
    # Argument (optional): all
    #
    # "docker-reset" will stop and remove all containers (except dinghy_http_proxy) and custom networks
    #
    # "docker-reset all" will reset the docker environment to clean slate (you will lose *all* volumes and custom networks!)
    #
    # Note: you'll need to install docker-clean: brew install docker-clean
    function docker-reset() {
    docker-kill-all
    echo "Running docker-clean..."
    docker-clean
    run_all=$1

    if [[ "${run_all} == "all" ]]; then
    docker-kill-all
    echo "Running docker-clean ..."
    docker-clean
    else
    docker-stop-all
    echo "Running docker-clean --networks ..."
    docker-clean --networks
    fi
    }
    # Purpose: Kill and remove all docker containers (except for dinghy_http_proxy)
    @@ -16,6 +30,15 @@ function docker-kill-all() {
    docker rm $(docker ps -a --filter "status=exited" -q) &> /dev/null
    }
    # Purpose: Stop and remove all docker containers (except for dinghy_http_proxy)
    function docker-stop-all() {
    PROXY=$(docker ps | grep dinghy_http_proxy | awk '{print $1}')
    echo "Stopping docker containers..."
    docker stop $(docker ps -q | grep -v $PROXY) &> /dev/null
    echo "Removing docker containers..."
    docker rm $(docker ps -a --filter "status=exited" -q) &> /dev/null
    }
    # Purpose: Delete all images related to the provided tag name
    # Example: `docker-nuke selenium` will delete all images whose tags contain the word "selenium"
    function docker-nuke() {
  7. mycargus revised this gist Apr 25, 2017. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions .bashrc
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,12 @@

    # Purpose: reset docker environment to clean slate (you will lose *all* volumes and custom networks!)
    # Note: you'll need to install docker-clean: brew install docker-clean
    function docker-reset() {
    docker-kill-all
    echo "Running docker-clean..."
    docker-clean
    }

    # Purpose: Kill and remove all docker containers (except for dinghy_http_proxy)
    function docker-kill-all() {
    PROXY=$(docker ps | grep dinghy_http_proxy | awk '{print $1}')
    @@ -8,14 +16,6 @@ function docker-kill-all() {
    docker rm $(docker ps -a --filter "status=exited" -q) &> /dev/null
    }

    # Purpose: reset docker environment to clean slate (you will lose *all* volumes and custom networks!)
    # Note: you'll need to install docker-clean: brew install docker-clean
    function docker-reset() {
    docker-kill-all
    echo "Running docker-clean..."
    docker-clean
    }

    # Purpose: Delete all images related to the provided tag name
    # Example: `docker-nuke selenium` will delete all images whose tags contain the word "selenium"
    function docker-nuke() {
  8. mycargus revised this gist Apr 25, 2017. 1 changed file with 10 additions and 9 deletions.
    19 changes: 10 additions & 9 deletions .bashrc
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,4 @@

    # Purpose: Delete all images related to the provided tag name
    # Example: `docker-nuke selenium` will delete all images whose tags contain the word "selenium"
    function docker-nuke() {
    args=("$@")
    docker ps -a | grep ${args[0]} | cut -d ' ' -f 1 | while read ID; do docker rm $ID; done;
    docker images | grep ${args[0]} | tr -s " " | cut -d ' ' -f 3 | while read ID; do docker rmi $ID; done
    }

    # Purpose: Kill and remove all docker containers (except for dinghy_http_proxy)
    function docker-kill-all() {
    PROXY=$(docker ps | grep dinghy_http_proxy | awk '{print $1}')
    @@ -16,13 +8,22 @@ function docker-kill-all() {
    docker rm $(docker ps -a --filter "status=exited" -q) &> /dev/null
    }

    # Purpose: reset docker environment to clean slate
    # Purpose: reset docker environment to clean slate (you will lose *all* volumes and custom networks!)
    # Note: you'll need to install docker-clean: brew install docker-clean
    function docker-reset() {
    docker-kill-all
    echo "Running docker-clean..."
    docker-clean
    }

    # Purpose: Delete all images related to the provided tag name
    # Example: `docker-nuke selenium` will delete all images whose tags contain the word "selenium"
    function docker-nuke() {
    args=("$@")
    docker ps -a | grep ${args[0]} | cut -d ' ' -f 1 | while read ID; do docker rm $ID; done;
    docker images | grep ${args[0]} | tr -s " " | cut -d ' ' -f 3 | while read ID; do docker rmi $ID; done
    }

    # Purpose: Remove all images
    function docker-rmi-all() {
    docker rmi -f $(docker images -q)
  9. mycargus revised this gist Apr 25, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion .bashrc
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@

    # Purpose: Delete all images related to the provided tag name
    # Example: `docker-nuke selenium` will delete all containers and images related to "selenium"
    # Example: `docker-nuke selenium` will delete all images whose tags contain the word "selenium"
    function docker-nuke() {
    args=("$@")
    docker ps -a | grep ${args[0]} | cut -d ' ' -f 1 | while read ID; do docker rm $ID; done;
  10. mycargus revised this gist Apr 25, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion .bashrc
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@

    # Purpose: Delete all containers and images related to the provided tag name
    # Purpose: Delete all images related to the provided tag name
    # Example: `docker-nuke selenium` will delete all containers and images related to "selenium"
    function docker-nuke() {
    args=("$@")
  11. mycargus revised this gist Apr 11, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions .bashrc
    Original file line number Diff line number Diff line change
    @@ -7,9 +7,9 @@ function docker-nuke() {
    docker images | grep ${args[0]} | tr -s " " | cut -d ' ' -f 3 | while read ID; do docker rmi $ID; done
    }

    # Purpose: Kill and remove all docker containers (except for dinghy-http-proxy)
    # Purpose: Kill and remove all docker containers (except for dinghy_http_proxy)
    function docker-kill-all() {
    PROXY=$(docker ps | grep dinghy-http-proxy | awk '{print $1}')
    PROXY=$(docker ps | grep dinghy_http_proxy | awk '{print $1}')
    echo "Killing docker containers..."
    docker kill $(docker ps -q | grep -v $PROXY) &> /dev/null
    echo "Removing docker containers..."
  12. mycargus created this gist Mar 20, 2017.
    36 changes: 36 additions & 0 deletions .bashrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@

    # Purpose: Delete all containers and images related to the provided tag name
    # Example: `docker-nuke selenium` will delete all containers and images related to "selenium"
    function docker-nuke() {
    args=("$@")
    docker ps -a | grep ${args[0]} | cut -d ' ' -f 1 | while read ID; do docker rm $ID; done;
    docker images | grep ${args[0]} | tr -s " " | cut -d ' ' -f 3 | while read ID; do docker rmi $ID; done
    }

    # Purpose: Kill and remove all docker containers (except for dinghy-http-proxy)
    function docker-kill-all() {
    PROXY=$(docker ps | grep dinghy-http-proxy | awk '{print $1}')
    echo "Killing docker containers..."
    docker kill $(docker ps -q | grep -v $PROXY) &> /dev/null
    echo "Removing docker containers..."
    docker rm $(docker ps -a --filter "status=exited" -q) &> /dev/null
    }

    # Purpose: reset docker environment to clean slate
    function docker-reset() {
    docker-kill-all
    echo "Running docker-clean..."
    docker-clean
    }

    # Purpose: Remove all images
    function docker-rmi-all() {
    docker rmi -f $(docker images -q)
    }

    # Purpose: slap virtualbox
    # Example: Using virtualbox as the VM for dinghy's docker host sometimes causes image download
    # latency. Run this function in a separate shell window when that happens.
    function slap-virtualbox() {
    while true; do dinghy ssh echo "turbo mode activated"; done
    }