58

I created a local docker registry and then pull some of my docker images from docker hub and then push them to the local registry. Now I want to remove my local images. But the problem here is that imageID of the images are the same and I cannot remove them. I searched for the solution but I couldn't find the solution.

>> docker images

REPOSITORY                     TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
localhost:5000/[repo1]        v-0.9.1              810001cb03af        4 weeks ago         594.6 MB
[myaccount]/[repo1]           v-0.9.1              810001cb03af        4 weeks ago         594.6 MB

as you see the image ID are the same for both images. How can I remove them?

EDIT

  • my docker version:

    Docker version 1.8.2, build 0a8c2e3

  • output of docker rmi 810001cb03af:

    Error response from daemon: Conflict, cannot delete image 810001cb03af because it is tagged in multiple repositories, use -f to force Error: failed to remove images: [810001cb03af]

  • If I do docker rmi -f 81000 it will remove both of them and I need to pull again.

4
  • What does docker rmi 810001cb03af returns? What version of docker are you using?
    – VonC
    Oct 5, 2015 at 8:48
  • @VonC I update my question. My docker is 1.8.2. The output of docker rmi 8100 added
    – Hadi
    Oct 5, 2015 at 8:56
  • @Constantine : Does the answer provided solve your problem. Feedback is helpful for anyone reading this issue or who may face similar issue in future.
    – spectre007
    Oct 6, 2015 at 1:49
  • @VonC I'm afraid not! Yes I'll do it as I find a solution. Thank you for your reminder :)
    – Hadi
    Oct 6, 2015 at 6:47

8 Answers 8

76

Here is a way you could do this. Run the command:

docker images | grep 810001cb03af | awk '{print $1 ":" $2}' | xargs docker rmi

where 810001cb03af is your image id.

6
  • 4
    Your approach will remove both images. I want to remove just the one that is on the local.
    – Hadi
    Oct 6, 2015 at 6:49
  • So you want to download only one image, not 2? Does this work then? 'docker rmi localhost:5000/[repo1]' Oct 7, 2015 at 9:08
  • Getting error: grep : The term 'grep' is not recognized as the name of a cmdlet Aug 1, 2017 at 7:15
  • @ManjeetSinghChauhan if you do not have grep installed, that will not work. I have not checked how you could do this on Windows. Maybe using Cygwin or BashOnWindows? Aug 7, 2017 at 21:25
  • Very useful. This came in handy when removing few tens of images. I used "docker images | grep "<none>" | awk '{print $3}' | xargs docker rmi -f" to get to container id Jul 12, 2019 at 15:28
45

Here is one way :

Repository and tag data can be provided to "docker rmi" command to remove image if images id are same.

command

docker rmi [repository_name1]:[tag1] [repository_name2]:[tag2]

example

docker rmi test-nginx:latest ubuntu:latest

Note : one needs to name and tag the image appropriately to use the above command effectively for requirement mentioned in the question.

Refer Docker docs for "docker rmi" command help : here

2
29

Short Answer:

Remove it by id and use -f flag:

$ docker rmi -f fd484f19954f

Untagged: test1:latest
Untagged: test2:latest
Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8

Explanation

These are not multiple images with same id. This is actually one image that is referenced in multiple repositories (i.e. given multiple names/tags). This scenario is described exactly in rmi command documentation

You can remove an image using its short or long ID, its tag, or its digest. If an image has one or more tag referencing it, you must remove all of them before the image is removed. Digest references are removed automatically when an image is removed by tag.

Given,

$ docker images

REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
test1                     latest              fd484f19954f        23 seconds ago      7 B (virtual 4.964 MB)
test2                     latest              fd484f19954f        23 seconds ago      7 B (virtual 4.964 MB)

You can, as an alternative to the short answer above, remove tags one by one (the last tag will actually remove the image too):

$ docker rmi test1:latest

Untagged: test1:latest

$ docker rmi test2:latest

Untagged: test2:latest
Deleted: fd484f19954f4920da7ff372b5067f5b7ddb2fd3830cecd17b96ea9e286ba5b8
2
  • For my case, I had to specify the tag to untag by repository name: docker rmi test1:[tagNumber]
    – user666
    Feb 17, 2020 at 6:36
  • 1
    yes, only the latest tag can be omitted because it is the default one. Any other tags would have to be specified explicitly. I have added the tag to the answer to be more generic. Feb 17, 2020 at 11:53
8

Run the following command to remove multiple docker images with the same IMAGE ID.

sudo docker rmi -f **IMAGE ID**
0
1

You can use the command docker rmi IMAGE_NAME:TAG_NAME and it will work.

1

There are multiple ways you can delete.

a) delete only one:

$ sudo docker rmi login(REPOSITORY NAME):latest(TAG NAME)

b) delete all with matching id with -f command:

$ sudo docker rmi -f 91dfd8adbf04(IMAGE ID)
0

I just checked in the Docker docs and i think this is something also can be done

rmi

You can remove an image using its short or long ID, its tag, or its digest. If an image has one or more tag or digest reference, you must remove all of them before the image is removed.

so rather than using ID u can do something like this ---

$ docker rmi test1 Untagged: test1:latest $ docker rmi test2 Untagged: test2:latest

1
  • yes i tried it ... when you do docker rmi [myaccount]/[repo1] it will show you ..... Untagged: [myaccount]/[repo1] and will remove the image .... i hope this is something what you wanted.. Oct 13, 2015 at 6:51
0

You should try removing images using digest,

    $ docker images --digests

    REPOSITORY                     TAG       DIGEST                                                                    IMAGE ID        CREATED         SIZE
    localhost:5000/test/busybox    <none>    sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf   4986bf8c1536

    $ docker rmi localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf
     Untagged: localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf

    Deleted: 4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125
    Deleted: ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2
    Deleted: df7546f9f060a2268024c8a230d8639878585defcc1bc6f79d2728a13957871b

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.