383
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
basickarl
  • 37,187
  • 64
  • 214
  • 335

37 Answers37

518

You can try and list only untagged images (ones with no labels, or with label with no tag):

docker images -q -a | xargs docker inspect --format='{{.Id}}{{range $rt := .RepoTags}} {{$rt}} {{end}}'|grep -v ':'

However, some of those untagged images might be needed by others.

I prefer removing only dangling images:

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

As I mentioned for for docker 1.13+ in Sept. 2016 in "How to remove old and unused Docker images", you can also do the image prune command:

docker image prune

tansadio suggests:

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

But, as noted by BryanK: make sure your repository name (or one of your tag names) does not have the sequence of characters 'none' or those will match the regular expression and get removed too.


That being said, Janaka Bandara mentions in the comments:

This did not remove <none>-tagged images for me (e.g. foo/bar:<none>); I had to use docker images --digests and docker rmi foo/bar@<digest>

Janaka references "How to Remove a Signed Image with a Tag" from Paul V. Novarese:

# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
pvnovarese/mprime        latest              459769dbc7a1        5 days ago          4.461 MB
pvnovarese/mprime        <none>              459769dbc7a1        5 days ago          4.461 MB

Diagnostic Steps

You can see the difference in these two entries if you use the --digests=true option (the untagged entry has the Docker Content Trust signature digest):

# docker images --digests=true
REPOSITORY               TAG                 DIGEST                                                                    IMAGE ID            CREATED             SIZE
pvnovarese/mprime        latest              <none>                                                                    459769dbc7a1        5 days ago          4.461 MB
pvnovarese/mprime        <none>              sha256:0b315a681a6b9f14f93ab34f3c744fd547bda30a03b55263d93861671fa33b00   459769dbc7a1        5 days ago     

Note that Paul also mentions moby issue 18892:

After pulling a signed image, there is an "extra" entry (with tag <none>) in "docker images" output.
This makes it difficult to rmi the image (you have to force it, or else first delete the properly-tagged entry, or delete by digest.


This thread also proposes:

First, you need to change the tag of the specific image you want to remove.

docker tag container_id repo_name:new_tag_name

# example 
docker tag 1234567er34r davesaah/my-repo:old

Next, remove the image with the new tag created using docker rmi

docker rmi repo-name:tag

# using the previous example 
docker rmi davesaah/my-repo:old

This will remove the dangling image that has dependent child images.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 20
    This did not remove ``-tagged images for me (e.g. `foo/bar:`); I had to use `docker images --digests` and `docker rmi foo/bar@` as described at https://success.docker.com/KBase/How_to_Remove_a_Signed_Image_with_a_%3Cnone%3E_Tag – Janaka Bandara Aug 12 '17 at 05:02
  • 1
    @JanakaBandara Thank you. I have included your comment in the answer (with some additional links) – VonC Aug 12 '17 at 05:39
  • for me `sudo docker rmi $(docker images --filter "dangling=true" -q --no-trunc)` `Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.35/images/json?filters=%7B%22dangling%22%3A%7B%22true%22%3Atrue%7D%7D: dial unix /var/run/docker.sock: connect: permission denied "docker rmi" requires at least 1 argument. See 'docker rmi --help'. Usage: docker rmi [OPTIONS] IMAGE [IMAGE...] [flags] Remove one or more images ` – Jamie Hutber Feb 07 '18 at 14:39
  • @JamieHutber "docker rmi" requires at least 1 argument. That suggests docker images --filter "dangling=true" -q --no-trunc returns nothing, meaning there is no dangling images? – VonC Feb 07 '18 at 14:42
  • Thanks VonC actually it doesn't `hutber@hutber-blade /var/www/dockerfile-wizard $ sudo docker images --filter "dangling=true" -q --no-trunc sha256:c58f4e4b10b1f862d78f96e90bdf13ffe37993279d0992be46d5c15dad51421e sha256:db28e821bc3f337caf711a664bc529be5db8894dd73c5b013ad814cc1e9fc21b sha256:257936750a7d43ae77c713c2cb18342be935de7d3b8fad23d6664fc64acfe753 sha256:6b815cefeb527885b2b9dd831f7f40b05942f00d1367274833a6274154d8ce43 ` – Jamie Hutber Feb 07 '18 at 15:58
  • tks, "docker image prune -f" is the official one to remove dangling none:none images – Dee Jun 14 '20 at 00:36
  • docker image prune did the job for me. – Sundeep Nov 03 '20 at 19:39
  • The correct answer is from @tansadio below – ejkitchen Oct 28 '22 at 01:20
  • Your second line was the solution for me. I'd prefer not to mess around with prune since it can erase absolutely everything I have as a docker image. – Lucas Camino Jan 24 '23 at 02:29
  • @LucasCamino Good point, especially since I just edited my [`docker prune` answer](https://stackoverflow.com/a/32723127/6309) to explain why there is no "`--dry-run`" mode for those prune commands. – VonC Jan 24 '23 at 06:47
  • 1
    docker image prune -> it had work for me! – childofthealgorithm Apr 16 '23 at 14:26
143
docker images -a | grep none | awk '{ print $3; }' | xargs docker rmi

You can try this simply

Nagev
  • 10,835
  • 4
  • 58
  • 69
tansadio
  • 1,439
  • 1
  • 7
  • 2
  • 17
    Have to add `--force` at the end. So the command will look like- `docker images | grep none | awk '{ print $3; }' | xargs docker rmi --force` – Munim Apr 17 '20 at 10:43
  • @MunimDibosh Just add `-f` at end of the commend from answer. – Eric Oct 29 '20 at 09:35
  • 5
    Had to add a `-a` to docker images to make it work: `docker images -a | grep none | awk '{ print $3; }' | xargs docker rmi --force`. – bappak Dec 16 '20 at 18:06
  • Just make sure your repository name (or one of your tag names) does not have the sequence of characters 'none' or those will match the regular expression and get removed too – BryanK Aug 08 '22 at 19:21
61

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.

herm
  • 14,613
  • 7
  • 41
  • 62
54

Just run this command:

docker image prune --filter="dangling=true"
Ragnar
  • 4,393
  • 1
  • 27
  • 40
28

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.

OzzyCzech
  • 9,713
  • 3
  • 50
  • 34
25

this worked in my case

docker image rm -f $(docker images -f dangling=true -q)
keshav swami
  • 551
  • 1
  • 6
  • 11
14

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}')
Seboudry
  • 448
  • 6
  • 15
Jerome Anthony
  • 7,823
  • 2
  • 40
  • 31
14

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
eQ19
  • 9,880
  • 3
  • 65
  • 77
10

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
OzzyCzech
  • 9,713
  • 3
  • 50
  • 34
GHETTO.CHiLD
  • 3,267
  • 1
  • 22
  • 34
10

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
yevgeniy
  • 748
  • 9
  • 15
10
docker rmi --force $(docker images -q --filter "dangling=true")
Rafaf Tahsin
  • 7,652
  • 4
  • 28
  • 45
8

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.

nPcomp
  • 8,637
  • 2
  • 54
  • 49
8

First solution:

  1. First delete containers that are not used.

    docker ps -a | grep -v Up | awk '{ print $1; }' | xargs docker rm
    
  2. Delete all containers with none tags.

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

Second solution delete all with:

$ docker system prune -a


WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all images without at least one container associated to them
- all build cache

Are you sure you want to continue? [y/N]
7

you can use this commend in docker :

docker image prune

and for all container:

docker container prune
buddemat
  • 4,552
  • 14
  • 29
  • 49
soheil raoufi
  • 71
  • 1
  • 1
6

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

justjais
  • 344
  • 3
  • 13
5

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!

Rajath
  • 2,611
  • 8
  • 27
  • 43
5

The easiest solution to remove dangling (<none>) images should be:

docker image prune

Optionally you can add --force or -f to disable the prompt.

Pascal Z.
  • 111
  • 2
  • 4
5

docker container prune to remove all stopped containers firstly, then docker image prune to remove all dangling images.

docker container prune
docker image prune
Bruce Wen
  • 61
  • 1
  • 4
4

Just remove the images using their IDs:

# docker rmi 5e2dfc857e73 d053e988f23d ...
Daniel Borges
  • 329
  • 3
  • 5
4

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
}
3

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

AnhellO
  • 855
  • 1
  • 14
  • 16
sudhir tataraju
  • 1,159
  • 1
  • 14
  • 30
3

i've found this for windows:

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

reference: https://gist.github.com/sebagomez/b00bd9e3610abab55fefe3d69f3708ad

3
docker image rm $(docker images | grep none)
ambition_sky
  • 91
  • 1
  • 3
2

Run the following command to remove the images with docker rmi

docker images --filter "dangling=true"      
mhovd
  • 3,724
  • 2
  • 21
  • 47
  • Prune the containers first so that the images aren't being "used" by stopped containers . Then delete the dangling images. – Paul Bendevis Oct 18 '21 at 13:49
2

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
Elton Sandré
  • 372
  • 3
  • 7
2

The only thing that helped me here was

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

I had 2 images . These were also relatively large at 160MB and I didn't want them.

I tried docker images prune, but it didn't help.

docker images | grep none | awk '{ print $3; }' | xargs docker rmi This command returned the following:

Error response from daemon: conflict: 0d1227b90e3a cannot be deleted (must be forced) - image is being used by stopped container c2c01a8c0cc9. Error response from daemon: Conflict: 791026064837 cannot be deleted (must be forced) - image used by stopped container 53dee16ceb19.

There were also still containers that needed these images.

With docker container ls -a | grep "c2c01a8c0cc9" I could check which dependency it was.

With:

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

I have now deleted the images.

Since I no longer need this container, I deleted it with: docker container rm <container_name>

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
2

With Docker Desktop for Windows you can get rid of the dangling images with

docker image prune
Sergio Prats
  • 1,043
  • 1
  • 14
  • 19
1

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

Aditya Satyavada
  • 1,028
  • 1
  • 10
  • 14
1

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}')

Jogendra Kumar
  • 513
  • 5
  • 14
1

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
Vishrant
  • 15,456
  • 11
  • 71
  • 120
1

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}')
nur zazin
  • 1,018
  • 13
  • 13
1

Pruning all images with force would solve your issue

docker image prune -a --force

0

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.

TheExorcist
  • 1,966
  • 1
  • 19
  • 25
0

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

iamfaith
  • 1,097
  • 1
  • 7
  • 2
-2

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

  • The OP states that he did try this exact command already but it failed. Also, this answer has been given at least twice already. – CaringDev Apr 02 '19 at 14:43
-4

try

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

Updated

user2915097
  • 30,758
  • 6
  • 57
  • 59
-8
docker rmi $(docker images -a -q)

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

basickarl
  • 37,187
  • 64
  • 214
  • 335