Why the “none” image appears in Docker and how can we avoid it

后端 未结 5 1837
攒了一身酷
攒了一身酷 2020-12-08 05:14

When I run the docker-compose build command to rebuild an image in Docker because I had changed something in Dockerfile, sometimes I get \"none\" image tags. Ho

相关标签:
5条回答
  • 2020-12-08 05:22

    This will remove all dangling docker images in Windows:

    for /f %x in ('docker images -f "dangling=true" -q') do docker rmi %x
    
    0 讨论(0)
  • 2020-12-08 05:26

    Below are some parts from What are Docker <none>:<none> images?

    The Good <none>:<none>

    These are intermediate images and can be seen using docker images -a. They don't result into a disk space problem but it is definitely a screen real estate problem. Since all these <none>:<none> images can be quite confusing as what they signify.

    The Bad <none>:<none>

    These images are the dangling ones, which can cause disk space problems. These <none>:<none> images are being listed as part of docker images and need to be pruned.

    (a dangling file system layer in Docker is something that is unused and is not being referenced by any images. Hence we need a mechanism for Docker to clear these dangling images)

    So,

    • if your case has to do with dangling images, it's ok to remove them with:

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

      There is also the option of docker image prune but the client and daemon API must both be at least v1.25 to use this command.

    • if your case has to do with intermediate images, it's ok to keep them, other images are pointing references to them.

    Related documentation:

    • docker rmi
    • docker image rm
    • docker image prune
    0 讨论(0)
  • 2020-12-08 05:28

    There is little to add based on what @tgogos said except that it needs more upvoting.

    You can check image sizes of dangling and non-dangling images here:

    docker system df -v
    

    Don't be bugged by intermediate images. This way you oversee that the build process has been made more efficient by keeping intermediate images for each line of a Dockerfile, i.e. such a line can be skipped during the build process if no change occurred.

    0 讨论(0)
  • 2020-12-08 05:29

    To remove <none> layers use:

    docker rmi $(docker images --filter "dangling=true" -q --no-trunc)

    0 讨论(0)
  • 2020-12-08 05:42

    In my experience most of the <none> images are held by temporary containers. Due to Docker architecture those containers are preserved even after they stop. You can verify how many stopped containers you have using

    docker ps -a
    

    So to remove the <none> images you first need to remove the unneeded containers:

    docker container prune
    docker image prune
    

    The above two commands can be abbreviated to

    docker system prune
    
    0 讨论(0)
提交回复
热议问题