moby: [1.9.0 RC-2] docker rmi fails when removing images with multiple tags
Description of problem:
docker version
:
Client:
Version: 1.9.0-rc2
API version: 1.21
Go version: go1.4.2
Git commit: 60d36f7
Built: Fri Oct 23 02:01:24 UTC 2015
OS/Arch: linux/amd64
Server:
Version: 1.9.0-rc2
API version: 1.21
Go version: go1.4.2
Git commit: 60d36f7
Built: Fri Oct 23 02:01:24 UTC 2015
OS/Arch: linux/amd64
docker info
:
Containers: 1
Images: 4
Server Version: 1.9.0-rc2
Storage Driver: overlay
Backing Filesystem: extfs
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 4.2.0-1-amd64
Operating System: Debian GNU/Linux stretch/sid (containerized)
CPUs: 4
Total Memory: 5.312 GiB
Name: ike
ID: 3TYO:NWYR:PAHR:FFIF:XCWO:H23J:RLA7:YOOQ:TUHP:AU2L:537X:G3GO
Username: jgkamat
Registry: https://index.docker.io/v1/
WARNING: No memory limit support
WARNING: No swap limit support
uname -a
:
Linux ike 4.2.0-1-amd64 #1 SMP Debian 4.2.3-2 (2015-10-14) x86_64 GNU/Linux
Environment details (AWS, VirtualBox, physical, etc.): Physical Machine, Debian Testing, Up to date (Oct 23)
How reproducible: Always
Steps to Reproduce: Right now, ubuntu:latest and ubuntu:14.04 point to the same image. Given that:
- Clean all images from docker host (for consistency)
docker pull ubuntu:14.04
docker pull ubuntu:latest
docker rmi $(docker images -q)
# Delete images based on ImageID
Actual Results:
[jay@ike ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu 14.04 1d073211c498 9 hours ago 187.9 MB
ubuntu latest 1d073211c498 9 hours ago 187.9 MB
[jay@ike ~]$ docker rmi $(docker images -q)
Error response from daemon: conflict: unable to delete 1d073211c498 (must be forced) - image is referenced in one or more repositories
Error response from daemon: conflict: unable to delete 1d073211c498 (must be forced) - image is referenced in one or more repositories
Error: failed to remove images: [1d073211c498 1d073211c498]
Expected Results: Both images deleted successfully.
Additional info:
Might be related to #16890? I don’t know though.
I’m pretty sure this was working in 1.9.0 RC-1, and this was definitely working on 1.8.3.
Is this expected (new) behavior? I’m pretty sure some automation somewhere relies on docker rmi $(docker images -q)
to delete all images.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 22 (21 by maintainers)
I think the problem in this case is that the image ID you are removing has more than 1 named reference. See https://github.com/docker/docker/pull/15606#issuecomment-134744099
The way that the maintainers intend for people to use Images is to never (ideally) have any unreferenced image IDs and that users would hopefully always refer to images by a given name rather than the randomly generated ID.
One usability issue with the CLI wrt images is that there exists no separate command for simply dereferencing (or _un_tagging) an image.
docker rmi
is overloaded to perform both actions. Because we want users to be careful to never accidentally delete an image that is referenced multiple times, it’s currently not allowed unless you force it.What would probably work for you is if you referenced the image names when using
docker rmi
. Then you will not get this error.Let’s take a look at the issue you described in more detail:
docker images -q
produces only the IDs as output. You’ll notice that both of these images have the same ID, so your command is equivalent to running:Which attempts to delete the same image twice. First of all, assuming that the deletion did succeed, it would then immediately error out because when it gets to the second one an image with that ID would no longer exist. What you probably want to do is delete these images by their named references like so:
It’s a bit unfortunate to have to use
tail
andawk
here, but it’s the only way to programmatically generate a list of image references that you want to delete. In this form,docker rmi
knows that what you really want to do is untag these images. If there is no longer any references to those images and the image has no child images* then (and only then) will the images be removed.A good change to the
docker images
command would be an option to complement-q
which lists only the named references instead of the image IDs.Yep, I think to have the old behavior back, a
docker rmi -f $(docker images -q)
should work… doesn’t feel so bad. @jgkamat wdyt ?Having a
--format
flag ondocker images
(similar to the flag that’s recently been added todocker ps
) would definitely help here