247

Let's say I want to tag a Docker image, and make a typo. How do I remove the tag without removing the image itself? Neither the manpages nor the Docker documentation mention removing tags.

docker tag 0e5574283393 my-imaj
docker tag 0e5574283393 my-image
# docker untag my-imaj # There is no "docker untag"!
Mihai
  • 2,796
  • 3
  • 13
  • 12
  • 7
    For those who want to untag ``-tagged images like `foo/bar:`: 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:00

4 Answers4

329

If your image is tagged with more than one tag, then docker rmi will remove the tag, but not the image.

So in your example ...

# docker rmi my-imaj

... will remove that tag and leave the image present with the other correct tag.

Richard Corfield
  • 3,529
  • 1
  • 14
  • 11
  • 4
    Thanks. I wish they mentioned this in the documentation :-/ – Mihai Jul 03 '15 at 14:17
  • 1
    goddamnit...how do I remove the image via the tag? :) – Alexander Mills Jul 14 '17 at 20:41
  • 3
    If the tag I'm removing is the last one though, the image will get removed. So I wonder what is the answer to the question in the topic? How do I remove the tag and keep the image cached? – kub1x Oct 17 '17 at 12:57
  • My scenario is one image with a tag: 1) Remove the tag from the image, but keep the image cached, tagless. 2) Run `docker build` with the same tag, but possibly different `Dockerfile`. 3a) If the `Dockerfile` didn't change, the cached image is tagged back with the same tag. 3b) If the `Dockerfile` did change, the new image is tagged with the original tag and the old image will be removed using `docker image prune`. – kub1x Oct 17 '17 at 13:03
  • 10
    And the answer is as always *use `--help`*, don't be lazy to read. `docker image remove --no-prune`.. in case somebody is interested. – kub1x Oct 18 '17 at 09:58
  • 9
    **This is false, it simply removed my image.** Fortunately, knowing docker I was already suspicious, and created a backup before with `docker save`. – peterh Oct 09 '18 at 14:06
  • 7
    @peterh the answer clearly states `If your image is tagged with more than one tag...`, it should be updated however with the command from the comments that explains how to remove the last tag without removing the image. – BrainSlugs83 Jul 20 '19 at 01:53
52

Run docker rmi REPOSITORY:TAG to remove the tag.

The REPOSITORY and TAG values come from docker images output.

For example

$ docker rmi my-image:0e5574283393
Untagged: my-image:0e5574283393
Dennis
  • 109
  • 4
ashishjain
  • 621
  • 4
  • 2
28

Starting from an empty docker repo, import an image by typing:

#docker run hello-world

Run the docker images command to list the images. The result should look like this:

REPOSITORY        TAG           IMAGE ID          CREATED           SIZE
hello-world       latest        7bc42cc48a84      4 weeks ago       316MB

Now let's create an image tag called v1 by running the docker tag command:

#docker tag hello-world:latest hello-world:v1

If we run the docker images command we'll see our new tag like this:

REPOSITORY        TAG           IMAGE ID          CREATED           SIZE
hello-world       latest        7bc42cc48a84      4 weeks ago       316MB
hello-world         v1          7bc42cc48a84      4 weeks ago       316MB

To delete a specific tag (to answer the original question), run the docker rmi hello-world:v1 where v1 is the tag name. The output will look like this:

#docker rmi hello-world:v1
Untagged: hello-world:v1

Run the docker images command to list the images. Notice that the image tag has been removed:

REPOSITORY        TAG           IMAGE ID          CREATED           SIZE
hello-world       latest        7bc42cc48a84      4 weeks ago       316MB
1

Tag other image with you tag name and afterwards your tag from your current image will be removed.

Nikolay
  • 11
  • 1