Skip to content

Instantly share code, notes, and snippets.

@nicovillanueva
Last active August 31, 2015 19:42
Show Gist options
  • Save nicovillanueva/c4516ea49d8878713e87 to your computer and use it in GitHub Desktop.
Save nicovillanueva/c4516ea49d8878713e87 to your computer and use it in GitHub Desktop.

Docker utilities

Just some quick functions to work with Docker, Machine and Swarm.

Copy it into your home, source it using your .bashrc and enjoy:
echo "source .bash_docker_funcs.sh" >> $HOME/.bashrc

docker-remove-all(){
echo "Really remove all docker containers? (y/N)"
read CONFIRM
if [[ $CONFIRM == "y" ]]; then
docker rm $(docker ps -aq)
fi
}
docker-show-env(){
env | grep DOCKER_
}
docker-set-env() {
eval $(docker-machine env $1)
}
docker-set-swarm-env() {
eval $(docker-machine env --swarm $1)
}
docker-stop-all(){
docker stop $(docker ps -q)
}
docker-kill-all(){
docker kill $(docker ps -q)
}
docker-unset-env(){
unset DOCKER_TLS_VERIFY
unset DOCKER_HOST
unset DOCKER_CERT_PATH
unset DOCKER_MACHINE_NAME
}
docker-clean-dangling() {
docker rmi $(docker images -q -f dangling=true)
}
docker-clean-volumes(){
if [[ -f ./.docker-cleanup-volumes.sh ]]; then
sudo ./.docker-cleanup-volumes.sh $1
else
echo -e "Docker volumes cleanup script not found as './.docker-cleanup-volumes.sh'.\nDownload it from:\nhttps://raw.githubusercontent.com/chadoe/docker-cleanup-volumes/master/docker-cleanup-volumes.sh"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment