原创Docker技术分享

Docker常用的清除容器镜像命令

2018-02-01  本文已影响189人  IT锟

杀死所有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/

上一篇下一篇

猜你喜欢

热点阅读