美文网首页原创Docker技术分享
Docker常用的清除容器镜像命令

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

作者: IT锟 | 来源:发表于2018-02-01 20:03 被阅读189次

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

    相关文章

      网友评论

        本文标题:Docker常用的清除容器镜像命令

        本文链接:https://www.haomeiwen.com/subject/mxrjzxtx.html