Docker: How to delete all local Docker images

后端 未结 16 2187
梦谈多话
梦谈多话 2021-01-29 17:24

I recently started using Docker and never realized that I should use docker-compose down instead of ctrl-c or docker-compose stop to get r

16条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-29 17:43

    For Unix

    To delete all containers including its volumes use,

    docker rm -vf $(docker ps -a -q)
    

    To delete all the images,

    docker rmi -f $(docker images -a -q)
    

    Remember, you should remove all the containers before removing all the images from which those containers were created.

    For Windows

    In case you are working on Windows (Powershell),

    $images = docker images -a -q
    foreach ($image in $images) { docker image rm $image -f }
    

    Based on the comment from CodeSix, one liner for Windows Powershell,

    docker images -a -q | % { docker image rm $_ -f }
    

    For Windows using command line,

    for /F %i in ('docker images -a -q') do docker rmi -f %i
    

提交回复
热议问题