Sunday, February 12, 2017

Quick Docker environment cleanup

Just a quick reference on my docker usage.

When working / playing with docker a lot, you quite often end up with a ton of containers and volumes laying around after they are needed...

Here are a couple tips I use to keep my environment clean.

On Windows 10
If you are using GitBash create a .bashrc and include the commands below:

alias docker-rm='docker rm $(docker ps -q -f status=exited)'
alias docker-rmi='docker rmi $(docker images -q -f dangling=true)'
alias docker-rmv='docker volume rm $(docker volume ls -q -f dangling=true)'

For MacOS X 
Add the following to your .bash_profile:

docker-rm(){
docker rm $(docker ps -q -f status=exited)
}
docker-rmv(){
docker volume rm $(docker volume ls -q -f dangling=true)
}
docker-rmi(){
docker rmi $(docker images -q -f dangling=true)
}
docker-update-all() {
docker images | awk '(NR>1) && ($2!~/none/) {print $1":"$2}'| xargs -L1 docker pull
}


Then simply run docker-rm, docker-rmi and docker-rmv to remove all the dangly bits :)

docker-update-all, is a handy way to get the latest images from docker hub.

No comments:

Post a Comment

Popular Posts

Followers