Skip to content

Instantly share code, notes, and snippets.

@mycargus
Last active December 6, 2016 19:00
Show Gist options
  • Save mycargus/e0142a812258492e806ac9ab021bd225 to your computer and use it in GitHub Desktop.
Save mycargus/e0142a812258492e806ac9ab021bd225 to your computer and use it in GitHub Desktop.
These bash functions make for quick docker work.
######################
####### DOCKER #######
######################
# 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}')
docker kill $(docker ps -q | grep -v $PROXY) &> /dev/null
docker rm $(docker ps -a --filter "status=exited" -q) &> /dev/null
}
# Purpose: Remove all images
# Note: works great with docker-clean (brew install docker-clean), e.g. `docker-kill-all && docker-clean`
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment