Issue
I've been always struggling with docker when it comes to common tasks, like removing all exited
containers, killing them or doing some maintenance tasks with docker images. Is there a way to define a docker command alias like we have in git, for example
[alias]
last-commit = show --pretty=format: --name-only HEAD^{commit}
I would like to define a command to remove all exited containers, for example
instead of this
docker rm $(docker ps -a -f status=exited -q)
I would like to do this
docker clean
Solution
There are some ways to do. One easy way is to set function in your .profile
or .bashrc
docker_clean() {
docker rm $(docker ps -a -f status=exited -q)
}
then you can run docker_clean
directly in shell.
There is a lot of projects in github you can refer to set functions
or alias
, here I list some of them.
Answered By - BMW Answer Checked By - Marie Seifert (WPSolving Admin)