Docker Community Forums

Share and learn in the Docker community.

How to remove <none> images after building


(Miniserver) #1

After I build my image, there are a bunch of images. When I try to delete them I get “image has dependent child images” errors. Is there anyway to clean this up?

These do NOT work:

docker rmi $(docker images -q)
docker rmi $(docker images | grep “^” | awk “{print $3}”)
docker rmi $(docker images -f “dangling=true” -q)


(Kostasmistos) #2

You should do
docker images -f “dangling=true” -q this will print you all the dangling images (untagged images)

the filtering also works for dangling volumes.


(Miniserver) #3

That didn’t do anything. They are still there:


(Kostasmistos) #4

yes that’s because the command only shows the _< none >_images
you need to remove them like
docker rmi $(docker images -f “dangling=true” -q)


(Miniserver) #5

Sorry, I didnt mention that I did put it in docker rmi. But, that didn’t work either.


(Kostasmistos) #6

I see. Try this
docker rmi $(docker images --filter “dangling=true” -q --no-trunc)
I always do it like that and it works


(Michael T Wells) #7

When you build your images add “–rm” this should help with removing any intermediate and none images.

‘’‘docker build --rm ‘’’


(Miniserver) #8

docker images --filter “dangling=true” -q --no-trunc
this doesn’t print anything so I get an error “docker: “rmi” requires a minimum of 1 argument.” when I call docker rmi $(docker images --filter “dangling=true” -q --no-trunc)

[quote]When you build your images add “–rm” this should help with removing any intermediate and none images.

‘’‘docker build --rm ‘’’
[/quote]
I do build with this but this only removes containers not images. The results of docker images -a shows images with “none”


(David Maze) #9

The results of docker images -a shows images with “none”

docker images -a will always show lots of “none” images, since it shows every layer of every image. If you run, for instance, docker history apache:latest, you should see all of the intermediate layer IDs. Those are included in the docker images -a output and can’t be removed.


(Dvohra) #10

To remove all dangling Docker images:
sudo docker rmi $(sudo docker images -f “dangling=true” -q)

If run as root omit "sudo"
docker rmi $(docker images -f “dangling=true” -q)


(Jcounts) #11

Did you ever find a solution to this? I am running into the same problem and have tried everything mentioned here.


(Miniserver) #12

You cannot delete the intermediate images. This is a good article explaining it:


(Salimkabeer) #13

I try to clean space and It worked for me


(Vcassiano) #14

You can use the following command to clean these components

docker system prune

will be showed the message below:

WARNING! This will remove:
	- all stopped containers
	- all volumes not used by at least one container
	- all networks not used by at least one container
	- all dangling images

Just say yes and keep calm. :slight_smile:


(Balaji Janakiram) #15

Use: docker image prune -f. More details here.


(Nnsense) #16

tl;dr - They cannot be deleted: save your new image, delete all the images and load it back

For anyone landing here, please read carefully Docker’s documentation and previous answers: as stated before ‘<none>:<none>’ images are intermediate images created during a build command and are parents of the newly created and, again, cannot be deleted.

Commands like docker image prune -f will not delete that images, I’ve personally tested every command mentioned on this post and the only way I’ve found to achieve that is using docker save/load:

docker save --output image.tar ImageID-or-Name
docker image prune -fa
docker load --input image.tar

(Axpraka) #17

OPTION 1: using error handling (send error to /dev/null)

docker rmi $(docker images --filter "dangling=true" -q --no-trunc) 2>/dev/null

docker rmi $(docker images --filter “dangling=true” -q --no-trunc) command will try to remove all dangled images. Once it is cleaned (no more image left), it will throw error as docker rmi require at least one image name/id.

2>/dev/null will direct any error message to null, so it will do nothing if all image is cleaned up.


OPTION 1: (no error)

You can also try cleaning only when dangled image is available using if condition to avoid any error. Something like below:

if [ "$(docker images -f "dangling=true" -q | awk '{print $3}' | sort -u)x" != "x" ]
then
       docker rmi $(docker images --filter "dangling=true" -q --no-trunc)
fi

(John Rofrano) #18

It is important to understand why you have intermediate untagged images showing as <none> <none> in order to avoid them since, as you have seen, you can’t remove them if they are in use.

The reason untagged images happen is because you built an image, then you changed the Dockerfile and built that image again and it reused some of the layers from the previous build. Now you have an untagged image which cannot be deleted because some of it’s layers are being used by a new version of that image.

The solution is to:

  • Delete the new version of the image
  • Delete the untagged image and
  • Rebuild the new version of the image so that it owns all of the layers.

You will be left with a single tagged image that contains all of the layers of the previous untagged images and the new image.

~jr


(Songguri) #19

It won’t work if the ‘docker images -a’ list with different order in the future, however , the command can delete “<none>” tagged images below.

docker rmi $(docker images -a|grep "<none>"|awk '$1=="<none>" {print $3}')

(Huupv) #20

Hi miniserver,
you can refer remove all images as below

You can refer link https://goo.gl/ke9pmf to details remove all none images