How to remove <none> images after building

This worked for me :slight_smile:
docker rmi <image_ID> -f
Then you’ll see:
Deleted: sha256:e23dfs4hlkjlkjsdflksjdfosdflksdjf2rf239fi932i09329f0i2390if2903f0239f

sudo docker image rm cd14cecfdb3a -f

--force-rm seems to prevent leaving <none>:<none> images when I use docker-compose to build images like so:

docker-compose build --force-rm

I don’t know why it works. The doc (https://docs.docker.com/compose/reference/build/) says --force-rm always remove intermediate containers but not images.

This works for me.
docker image prune -f

docker images -f "dangling=true" -q lists one image per row, and docker rmi expects them to be separated by space rather than newline, so you have to join them together before calling docker rmi if there are multiple images that need to be removed. This is the command that works for me:

docker rmi $(docker images -f "dangling=true" -q | tr "\n" " ")

Thanks! Copy-paste does not work because of the quotes. But the code works anyhow.

you are right, but need in the powershell

Hi all,
I tried the docker rmi $(docker images -f “dangling=true” -q) command and it worked for me.

Great.also has this problem.
thanks for it

Try this:

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

… or instead of using grep and awk in pipes with docker’s build-in functionality:

docker image rm $(docker image ls --filter dangling=true -q)

It’s quite odd that docker rm does not accept the --filter argument.

All effective ways are fine as long as they get the job done :slight_smile:

you can use this command
docker image rm -f $(docker images | grep "<none>" | awk '{print$3}')

There is really no need for using grep and awk or any fancy long commands.

Just use:

docker image prune

and it will prune all dangling images.

3 Likes

This really help all issue above mention…

thank you so much it works for me

just wanted to add my command as well, just using pipes, if anybody finds it helpful

docker images  | grep '<none>' | awk '{print $3}' | xargs  docker image rm -f {}

Both docker image rm $(docker images --filter "dangling=true" -q --no-trunc) and docker image prune are equivalent. Both will only delete all images with no tag (dangling images). Unused, non-dangling images (images without a tag value of <none>) will not be deleted.

I’ve tried docker images prune -a but am still left with a <none> image.

I wonder if this is what’s happening.

I’m not sure how to follow the steps, though, because I’m completely new to programming. What are the breakdowns for each step? I’m on DigitalOcean.

The command to remove an image is:

docker rmi {image_name}

Where {image_name} is the name of the image you want to delete. You can also use the image ID to delete the image (e.g., docker rmi {image_id}). This is what you will need to use to delete an image with a name of <none>.

For example, Let’s say you have the following images:

REPOSITORY           TAG        IMAGE ID       CREATED              SIZE
my-new-image         latest     c18f86ab8daa   12 seconds ago       393MB
<none>               <none>     b1ee72ab84ae   About a minute ago   393MB
my-image             latest     f5a5f24881c3   2 minutes ago        393MB

It is possible that the <none> image cannot be deleted because the my-new-image is using some layers from it. What you need to do is:

docker rmi my-new-image:latest
docker rmi b1ee72ab84ae
docker built -t my-new-image .

What that does is remove my-new-image:latest which is reusing layers from the <none> image. It then deletes the <none> image using it’s image ID b1ee72ab84ae. Finally it rebuilds my-new-image creating all of the layers that are needed.

Also check to make sure that you don’t have stopped containers that are still using the <none> “untagged” image. Use docker ps -a to see all containers including ones that have exited. If so, use docker rm {container_id} to remove the container and then try and remove the <none> image again.

Hope that helps.

1 Like

Thank you for this super clear explanation!