[docker] Docker remove <none> TAG images

root@server:~# docker images -a        
REPOSITORY              TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>                  <none>              5e2dfc857e73        5 days ago          261.6 MB
<none>                  <none>              d053e988f23d        5 days ago          261.6 MB
<none>                  <none>              1d5d4a2d89eb        5 days ago          261.6 MB
<none>                  <none>              ea0d189fdb19        5 days ago          100.5 MB
<none>                  <none>              26c6175962b3        5 days ago          100.5 MB
<none>                  <none>              73d5cec4a0b3        5 days ago          100.5 MB
<none>                  <none>              e19590e1bac1        5 days ago          100.5 MB

I've tried the following:

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

And the following:

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

Get the following error:

docker: "rmi" requires a minimum of 1 argument.
See 'docker rmi --help'.

Usage:  docker rmi [OPTIONS] IMAGE [IMAGE...]

Remove one or more images

This question is related to docker

The answer is


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

Just run this command:

docker image prune --filter="dangling=true"

Just remove the images using their IDs:

# docker rmi 5e2dfc857e73 d053e988f23d ...

docker system prune will do the trick, it removes

- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache

But use it, with the caution!


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


The dangling images are ghosts from the previous builds and pulls, simply delete them with : docker rmi $(docker images -f "dangling=true" -q)


Its simple and clear,

Even I took 3 days to understand this simple and crisp error.

The docker image is not built successfully

Step 7/13 : COPY jupyter_notebook_config.py /root/.jupyter/
 ---> bf29ce6fe6dc
Step 8/13 : COPY notebooks /notebooks
COPY failed: stat /var/lib/docker/tmp/docker-builder776981166/notebooks: no such file or directory
anarchist@anarchist-desktop:~/Documents/sam/dockerDem$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              bf29ce6fe6dc        9 seconds ago       1.27GB
ubuntu              16.04               a51debf7e1eb        3 weeks ago         116MB

Then I removed the 8th line from Dockerfile, it was signal success this time.

Successfully built b6724370f8ca
Successfully tagged dem:expo
anarchist@anarchist-desktop:~/Documents/sam/dockerDem$ docker run -it -p 8888:8888 dem:expo
[I 06:11:38.984 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[I 06:11:39.011 NotebookApp] Serving notebooks from local directory: /
[I 06:11:39.011 NotebookApp] The Jupyter Notebook is running at:
[I 06:11:39.011 NotebookApp] http://(296d81166725 or 127.0.0.1):8888/?token=496feb282ef749c05277ef57a51e8a56fedb1c6b337b9f92

It says successfully tagged dem:expo, this line is imp during docker process.


To remove all images with none we have to be sure that we removed all stopped containers which they can use run:

docker rm $(docker ps -a -q)

then we can remove all images:

docker image prune

According to the docker documentation you can list only untagged (dangling) images with

$ docker images -f "dangling=true"

and redirect them to docker rmi command like that:

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

Notice -q param thats only show numeric IDs of containers.


try

docker rmi -f $(docker images -a | awk 'NR> 1 || $2 = "<none>" {print $3}') , while there may be cleaner commands

Updated


docker image prune removes all dangling images (those with tag none). docker image prune -a would also remove any images that have no container that uses them.

The difference between dangling and unused images is explained in this stackoverflow thread.


docker images | grep none | awk '{ print $3; }' | xargs docker rmi

You can try this simply


try this to see list docker images ID with tag <none>

docker images -a | awk '/^<none>/ {print $3}'

and then you can delete all image with tag <none>. this worked for me.

docker rmi $(docker images -a | awk '/^<none>/ {print $3}')

You can go docker rmi $(docker images -f "dangling=true" -q). See the images documentation for more options.

$ docker images
REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE
<none>                      <none>              94870cda569b        4 seconds ago       673MB
python                      2.7                 320a06f42b5f        10 days ago         673MB
mysql                       latest              e799c7f9ae9c        2 months ago        407MB
gcavalcante8808/semaphore   latest              86e863e11461        2 months ago        537MB
redis                       latest              e32ef7250bc1        2 months ago        184MB
rabbitmq                    3.6.9-management    7e69e14cc496        2 months ago        179MB
rabbitmq                    3.6.9               eb2e4968538a        2 months ago        179MB
jordan/rundeck              latest              6d40b57b1572        2 months ago        660MB
rabbitmq                    3.5.6-management    dbfe8d18809a        19 months ago       304MB

$ docker rmi $(docker images --format '{{.ID}}' --filter=dangling=true)
Deleted: sha256:94870cda569b8cf5f42be25af107d464c993b4502a1472c1679bf2d213b6c0a6

Remove images which have none as the repository name using the following:

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

Remove images which have none tag or repository name:

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

I have found docker image prune -f most useful and I use it all the time during my day to day work, using the tag -f will not prompt for confirmation. More details here


Following will remove all the <none> images

docker rmi $(docker images | grep none | awk '{print $3}')

You can force removal by changing docker rmi to docker rmi -f although I do not recommend doing that.

Some of the <none> images could be related to other images so to be on safe side don't use -f tag.


This is an extension of tansadio's answer:

If you are getting following error:

Error response from daemon: conflict: unable to delete <> (must be forced) - image is being used by stopped container <>

You can force it with --force:

docker images | grep none | awk '{ print $3; }' | xargs docker rmi --force

All

Sharing the PowerShell command for windows lovers (just in case you don't have bash, grep or awk)

(docker images) -like '*<none>*' | ForEach-Object { 
  $imageid=($_ -split "\s+")[2]
  docker rmi -f $imageid
}

100% works: docker images | grep none | awk '{print $3}' | xargs docker rmi -f


The below command is working for me. this is just simple grep "" images and get the docker image id and removed all the images. Simple single command as it has to.

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


Run the following command to remove the images with docker rmi

docker images --filter "dangling=true"      

docker rmi -f $(docker images -a|awk 'NR > 1 && $2 == "" {print $3}')


You may check if the filter 'dangling' is no more working

$ docker images -f “dangling=true” -q
Error response from daemon: Invalid filter 'dangling'

Use docker system prune to remove the dangling images

$ docker system prune
WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all dangling build cache
Are you sure you want to continue? [y/N]

You may use --force for not prompt for confirmation

$ docker system prune --force

Remove all exited containers

docker rm $(docker container ls -a -f status=exited -q)

or remove containers according to a pattern

docker images -a | grep "pattern" | awk '{print $3}' | xargs docker rmi

docker rmi $(docker images -a -q)

Stated the following images where in use. I think this command gets rid of unwanted images.


To remove dangling images please use :

docker image rm $(docker images --format "{{.ID}}" --filter "dangling=true")

Please refer to my answer here for a more detailed description : https://unix.stackexchange.com/a/445664/292327