Docker: How to delete all local Docker images

后端 未结 16 2183
梦谈多话
梦谈多话 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:36

    To delete all images :

    docker rmi $(docker images -a -q)
    

    where -a is all, and -q is return only image ids

    To remove unused images, and containers :

    docker system prune
    

    beware as if you are using docker swarm, and your local machine is joining remote swarm (as manager/worker), your local will be the deployed repo. executing this thus removes the deployed images.

    0 讨论(0)
  • 2021-01-29 17:37

    Here is short and quick solution I used

    Docker provides a single command that will clean up any resources — images, containers, volumes, and networks — that are dangling (not associated with a container):

    docker system prune
    

    To additionally remove any stopped containers and all unused images (not just dangling images), add the -a flag to the command:

    docker system prune -a
    


    For more details visit link

    0 讨论(0)
  • 2021-01-29 17:38

    docker image prune -a

    Remove all unused images, not just dangling ones. Add -f option to force.

    Local docker version: 17.09.0-ce, Git commit: afdb6d4, OS/Arch: darwin/amd64

    $ docker image prune -h
    Flag shorthand -h has been deprecated, please use --help
    
    Usage:  docker image prune [OPTIONS]
    
    Remove unused images
    
    Options:
      -a, --all             Remove all unused images, not just dangling ones
          --filter filter   Provide filter values (e.g. 'until=<timestamp>')
      -f, --force           Do not prompt for confirmation
          --help            Print usage
    
    0 讨论(0)
  • To simple clear everything do:

    $ docker system prune --all
    

    Everything means:

    • all stopped containers
    • all networks not used by at least one container
    • all images without at least one container associated to them
    • all build cache
    0 讨论(0)
  • 2021-01-29 17:40

    Easy and handy commands

    To delete all images

    docker rmi $(docker images -a)
    

    To delete containers which are in exited state

    docker rm $(docker ps -a -f status=exited -q)
    

    To delete containers which are in created state

    docker rm $(docker ps -a -f status=created -q)
    

    NOTE: Remove all the containers then remove the images

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题