Skip to content

Instantly share code, notes, and snippets.

@vshank77
Last active April 29, 2019 09:01
Show Gist options
  • Save vshank77/5e8ffa87d46cca166e5d to your computer and use it in GitHub Desktop.
Save vshank77/5e8ffa87d46cca166e5d to your computer and use it in GitHub Desktop.
Docker clean up commands
alias dockstart='docker-machine start default'
alias dockrestart='docker-machine restart default'
alias dockstop='docker-machine stop default'
alias dock='eval "$(docker-machine env default)"'
alias dockswm='eval "$(docker-machine env -swarm swarm-master)"'
alias dps='docker ps -a'
alias dqf='docker images -qf "dangling=true"'
alias ddqf='docker rmi -f $(docker images -qf "dangling=true")'
alias ddrmi='docker rmi -f $(docker images | grep -e "latest" -e "SNAPSHOT" | awk '"'"'{print $3}'"'"')'
alias dimg='docker images'
alias drmi='docker rmi'
alias drm='docker rm'
alias ddrm='docker rm $(docker ps --filter '"'"'status=exited'"'"' | awk '"'"'{if (NR>1) {print $1}}'"'"')'
alias dclean='docker volume rm $(docker volume ls -qf dangling=true)'
#evaluate a docker container
eval "$(docker-machine env default)"
#list dangling docker images
docker images -qf "dangling=true"
#list images matching a name or tag
docker images | grep 'polyglotted/pg-app-base'
#list images not matching a name or tag (inverse search)
docker images | grep -v 'polyglotted/pg-app-base'
#delete dangling docker images
docker rmi -f $(docker images -qf "dangling=true")
#delete images not matching a name or tag (inverse)
docker rmi -f $(docker images | grep -v 'latest' | awk '{if (NR>1) {print $3}}')
#list containers that have been stopped
docker ps --filter "status=exited"
#remove containers that have been stopped
docker rm $(docker ps --filter 'status=exited' | awk '{if (NR>1) {print $1}}')
#clean up docker spaces
docker volume rm $(docker volume ls -qf dangling=true)
#execute bash on docker
docker exec -i -t <<name>> bash
#hard reset git
git tag -d <tagId>
git push origin :refs/tags/<tagId>
git reset --hard HEAD~2
git push --force
#useful for checking docker ports
sudo netstat -plntu
#creating elb load balancer
aws elb create-load-balancer-policy --load-balancer-name my-load-balancer --policy-name EnableProxyProtocol --policy-type-name ProxyProtocolPolicyType --policy-attributes "AttributeName=ProxyProtocol,AttributeValue=true"
#
ssh-pgio() {
if [ -z "$1" ]; then
echo "Usage: $0 [ip address]"
exit 1
fi
ssh -o StrictHostKeyChecking=no -i ~/.ssh/pgio-admin.pem ubuntu@$1
}
getDockerIp() {
ping -c 1 `hostname` | grep "64 bytes" | awk '{print $4}' | rev | cut -c 2- | rev
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment