how to physically remove untagged docker images

前端 未结 6 1062
盖世英雄少女心
盖世英雄少女心 2021-02-04 02:39

when I run a command such as sudo docker rmi me/myimage I get the responce ...image untagged, but, when I rerun sudo docker images I can see that this \"untagged\" image i

相关标签:
6条回答
  • 2021-02-04 03:21

    If John Petrone solution doesn't work, try removing those images referring explicitly the IMAGE ID you see when you run docker images. You can remove all of them with one command

    for i insudo docker images | grep \ | awk '{print $3}'; do sudo docker rmi $i; done

    PD: I don't know John Petrone answer. It works nicely with Docker 1.4.1

    0 讨论(0)
  • 2021-02-04 03:22

    This commands also work

    docker rmi $(docker images | grep "^<none>" | awk '{print $3}')
    

    Delete images with force to forgo stopped containers that might be using image

    docker rmi -f $(docker images | grep "^<none>" | awk '{print $3}')
    
    0 讨论(0)
  • 2021-02-04 03:24

    This command will remove all the dangling images and containers from docker.

    docker system prune -f
    
    0 讨论(0)
  • First you need to remove exited containers, then remove dangling images.

    docker rm $(docker ps -q -f status=exited)
    docker rmi $(docker images -q -f dangling=true)
    

    After all, I created the below script as ~/bin/dclean and have been using it.

    #!/bin/sh
    
    processes=$(docker ps -q -f status=exited)
    if [ -n "$processes" ]; then
      docker rm $processes
    fi
    
    images=$(docker images -q -f dangling=true)
    if [ -n "$images" ]; then
      docker rmi $images
    fi
    
    0 讨论(0)
  • 2021-02-04 03:32

    You should be able to remove untagged Docker images using the "dangling=true" flag:

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

    source:

    https://docs.docker.com/engine/reference/commandline/images/

    0 讨论(0)
  • 2021-02-04 03:32

    you can delete single images by their image id...

    docker images
    docker rmi <image-id>
    
    0 讨论(0)
提交回复
热议问题