Untagging image not working
sw00choi opened this issue · 6 comments
If there are multiple tags for an image, "docker rmi " should untag the given tag from the image.
But, when i try to untag from the image, error occurs like this:
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 56465e1e45d2 4 weeks ago 0 B
> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bf26aabdf1e1 ubuntu "/bin/sh -c 'while tr" 2 minutes ago Up 3 minutes myubuntu
> docker tag ubuntu ubuntu:newtag
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu newtag 56465e1e45d2 4 weeks ago 0 B
ubuntu latest 56465e1e45d2 4 weeks ago 0 B
> docker rmi ubuntu:newtag
Error response from daemon: Conflict, cannot delete ubuntu:newtag because the running container bf26aabdf1e1 is using it, stop it and use -f to force (05edbea0-aa3e-11e6-97d4-9f4f8deb19ed)
Check via docker ps -a
that you don't have a stopped container bf26aabdf1e1
with that tag.
I tested again like this.
- I have an image and a container.
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 56465e1e45d2 4 weeks ago 0 B
> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8364d05b7aea ubuntu "/bin/sh -c 'while tr" About a minute ago Up About a minute myubuntu
- Then, I tagged the image like this:
> docker tag ubuntu:latest ubuntu:atag
> docker tag ubuntu:latest ubuntu:btag
> docker tag ubuntu:latest ubuntu:ctag
> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu atag 56465e1e45d2 4 weeks ago 0 B
ubuntu btag 56465e1e45d2 4 weeks ago 0 B
ubuntu ctag 56465e1e45d2 4 weeks ago 0 B
ubuntu latest 56465e1e45d2 4 weeks ago 0 B
- The
IMAGE
column of the result fromdocker ps -a
is changed toubuntu:atag
.
(It seems thatdocker ps -a
picks the first tag from the image's alphabetically ordered tag list.
Some user might be confused because it looks like the image of the running container has been changed.
But I don't think it's a big problem.)
> docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8364d05b7aea ubuntu:atag "/bin/sh -c 'while tr" 3 minutes ago Up 3 minutes myubuntu
- I want to untag
ubuntu:atag
,ubuntu:btag
, andubuntu:ctag
from the image, but error occurs as follows:
> docker rmi ubuntu:atag
Error response from daemon: Conflict, cannot delete ubuntu:atag because the running container 8364d05b7aea is using it, stop it and use -f to force (fc16b0c0-aaca-11e6-92c6-73e360e212e3)
> docker rmi ubuntu:btag
Error response from daemon: Conflict, cannot delete ubuntu:btag because the running container 8364d05b7aea is using it, stop it and use -f to force (ffadba30-aaca-11e6-92c6-73e360e212e3)
> docker rmi ubuntu:ctag
Error response from daemon: Conflict, cannot delete ubuntu:ctag because the running container 8364d05b7aea is using it, stop it and use -f to force (015576c0-aacb-11e6-92c6-73e360e212e3)
I could not get rid of any of those until I remove the container.
It means that before I remove any tag, all containers using the image should be removed.
(It seems that docker ps -a picks the first tag from the image's alphabetically ordered tag list. Some user might be confused because it looks like the image of the running container has been changed. But I don't think it's a big problem.)
That is the behavior of the upstream Docker implementation too (or at least was at one point). I agree that it's weird.
I could not get rid of any of those until I remove the container.
It means that before I remove any tag, all containers using the image should be removed.
I can confirm the behavior you're seeing and the upstream Docker implementation doesn't match this. There's an open JIRA DOCKER-163 that refers to this commit 51a1e2f where the behavior was implemented; it looks like we're not hitting this branch. I'll add a note to this in the open JIRA ticket and ping @twhiteman here.
Some workarounds in the meantime:
Option 1
You can delete all the tags associated with the image via docker rmi -f <short ID>
. The container will remain behind.
docker rmi -f a46650c13b46
Untagged: alpine:c
Untagged: alpine:b
Untagged: alpine:a
Untagged: alpine:latest
Deleted: a46650c13b46891f6d1cfc601acca45087ec4031df57b5bc06ea689330d694d7
Option 2
You can update the tag you want to delete to point to an image that you're not running a container for.
$ docker pull alpine:3.3
3.3: Pulling from alpine (req e78a60b0-ab39-11e6-a0a4-29f42d73db17)
ce2f9b63043b: Pull complete
Digest: sha256:75a6050d5237f432391a0e3fac37b44ee5b5c78158868a68cfaaf72e872a2176
Status: Downloaded newer image for alpine:3.3
$ docker pull alpine:latest
latest: Pulling from alpine (req ea7fd2f0-ab39-11e6-a0a4-29f42d73db17)
a46650c13b46: Already exists
Digest: sha256:fb76bd8c78f158a05b2d7b3ad624d4be0d094c6645a5c713883eb6af47553881
Status: Image is up to date for alpine:latest
$ docker tag alpine:latest alpine:atag
$ docker tag alpine:latest alpine:btag
$ docker tag alpine:latest alpine:ctag
$ docker run --name test1 alpine:ctag exit 1
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a07fe6b45c1b alpine "exit 1" 28 seconds ago Exited (17) 8 seconds ago test1
$ docker rmi alpine:ctag
Error response from daemon: Conflict, cannot delete alpine:latest because the container a07fe6b45c1b is using it, use -f to force (2dfd0bb0-ab3a-11e6-a0a4-29f42d73db17)
$ docker tag alpine:3.3 alpine:c
$ docker rmi alpine:c
Untagged: alpine:c
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a07fe6b45c1b alpine "exit 1" 2 minutes ago Exited (17) 2 minutes ago test1
Thanks - logging this as a bug here https://smartos.org/bugview/DOCKER-975, which should be fixed soon. Closing this issue.
Didn't realize sw00choi had already started a CR for this, so re-opening:
https://cr.joyent.us/#/c/890/