Docker清除容器镜像命令

by Web全栈工程师 on 2015 年 07 月 29 日

杀死所有running状态的容器

docker kill $(docker ps -q)

删除所有已经停止的容器

docker rm $(docker ps -a -q)

删除所有\’untagged/dangling\’ ()状态的镜像

docker rmi $(docker images -q -f dangling=true)

删除所有镜像:

docker rmi $(docker images -q)

为这些命令创建别名:

# ~/.bash_aliases

# Kill all running containers.
alias dockerkillall='docker kill $(docker ps -q)'

# Delete all stopped containers.
alias dockercleanc='printf "\n>>> Deleting stopped containers\n\n" && docker rm $(docker ps -a -q)'

# Delete all untagged images.
alias dockercleani='printf "\n>>> Deleting untagged images\n\n" && docker rmi $(docker images -q -f dangling=true)'

# Delete all stopped containers and untagged images.
alias dockerclean='dockercleanc || true && dockercleani'

参考资料:
https://www.calazan.com/docker-cleanup-commands/

Comments on this entry are closed.

Previous post:

Next post: