104

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. How can we avoid this fact? I want to rebuild the image but the none image should not appear.

REPOSITORY  TAG            IMAGE ID            CREATED             SIZE
magento2    latest         b4dce4dcbd4f        16 hours ago        516MB
<none>      <none>         b4ffce2bf91e        16 hours ago        519MB
<none>      <none>         a1aedb60c82a        17 hours ago        516MB
<none>      <none>         ec9a14ae856c        20 hours ago        519MB
<none>      <none>         ef8eba6874cc        23 hours ago        516MB
<none>      <none>         0e53a8b8c303        23 hours ago        516MB
php         7.1-apache     93e6fb4b13e1        3 weeks ago         369MB
mysql       5.6.39         079344ce5ebd        7 months ago        256MB
Chen Hanhan
  • 1,549
  • 6
  • 15
  • 20
  • 7
    A nice article is this: [What are Docker : images?](http://www.projectatomic.io/blog/2015/07/what-are-docker-none-none-images/). – tgogos Nov 09 '18 at 08:03
  • not, because I want to know the cause and the resolution of the problem, in this case the "none" image – Chen Hanhan Nov 09 '18 at 08:07
  • Possible duplicate of [What are repository and tags? Why do they appear when I use docker build?](https://stackoverflow.com/questions/30179716/what-are-none-repository-and-tags-why-do-they-appear-when-i-use-docker-build) – David Maze Nov 09 '18 at 09:42
  • I think the questions are different because I want to know also how can I avoid none image when I execute```docker-compose build``` – Chen Hanhan Nov 09 '18 at 09:53
  • The none image continues to appear with ```docker-compose build --force-rm``` – Chen Hanhan Nov 09 '18 at 10:21

6 Answers6

131

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:

tgogos
  • 23,218
  • 20
  • 96
  • 128
46

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
SnakE
  • 2,355
  • 23
  • 31
4

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.

Patrick
  • 407
  • 4
  • 7
1

You can remove dangling images using

docker rmi $(docker images -f "dangling=true" | grep "<none>.*<none>" | awk '{ print $3; }')
GC001
  • 871
  • 8
  • 12
0

This will remove all dangling docker images in Windows:

for /f %x in ('docker images -f "dangling=true" -q') do docker rmi %x
pinxau1000
  • 301
  • 1
  • 11
-1

To remove <none> layers use:

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

ntippman
  • 125
  • 2
  • 7