Skip to content

Instantly share code, notes, and snippets.

@gitawego
Last active October 19, 2021 19:53
Show Gist options
  • Select an option

  • Save gitawego/60a66674e9f325d53656d3f581d772c9 to your computer and use it in GitHub Desktop.

Select an option

Save gitawego/60a66674e9f325d53656d3f581d772c9 to your computer and use it in GitHub Desktop.
docker helper alias
dockerCleanUp(){
# remove exited containers:
docker ps --filter status=dead --filter status=exited --filter status=created -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
docker volume ls -qf dangling=true | xargs -r docker volume rm
}
dockerShell(){
docker exec -i -t $1 /bin/bash
}
gitCleanBranches(){
git fetch -p
if [ ! -z "`git branch -vv | awk '/: gone]/{print $1}'`" ];
then
git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d
else
echo "no branch to be cleaned"
fi
}
resetCommit(){
if [ -z $1 ];
then
echo "reset total histories required"
else
git reset --soft HEAD~$1
fi
}
function use_nvidia(){
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia $@
}
alias docker-cleanup=dockerCleanUp
alias docker-shell=dockerShell
alias git-clean-branches="git fetch -p && git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -d"
alias git-clean-branches=gitCleanBranches
alias git-reset-commit=resetCommit
alias node-update="nvm install node --reinstall-packages-from=node && nvm alias default node"
@gitawego

gitawego commented Jan 19, 2017

Copy link
Copy Markdown
Author

if you are using dotfile, put content to ~/.extra.
otherwise, put in ~/.bashrc

usage

# to clean up
docker-cleanup

# to log into a docker container

docker-shell your_container_name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment