docker-custodian icon indicating copy to clipboard operation
docker-custodian copied to clipboard

dcgc does not detect :latest automatically

Open schmunk42 opened this issue 9 years ago • 2 comments

I noticed when running dcgc that it tried to remove images from containers which have been started without any tag. If an image was started with :latest it does not try to remove it.

Kraftbuch:~ tobias$ docker run -ti     -v /var/run/docker.sock:/var/run/docker.sock     yelp/docker-custodian dcgc --max-image-age=30d
Getting all containers
Found 53 containers
Getting all images
Found 111 images
Removing image 52e2cc6d3b9132a2 tutum/couchdb:latest
Error calling remove_image tutum/couchdb:latest 409 Client Error: Conflict ("conflict: unable to remove repository reference "tutum/couchdb:latest" (must force) - container c11508d13abb is using its referenced image 52e2cc6d3b91")
Removing image 7c93d6e7947e2b74 yelp/docker-custodian:latest
Error calling remove_image yelp/docker-custodian:latest 409 Client Error: Conflict ("conflict: unable to remove repository reference "yelp/docker-custodian:latest" (must force) - container 38cbffb93181 is using its referenced image 7c93d6e7947e")

There's noting going wrong, but it would be nice if there could be a more exact parsing of the running images list.

Eg, I had this container running:

c11508d13abb        tutum/couchdb                        "/run.sh"                 26 minutes ago      Up 26 minutes

Surprisingly, if I start a container with docker run -d tutum/couchdb:latest it does not try to remove any of tutum/couchdb or tutum/couchdb:latest.

schmunk42 avatar Jan 25 '16 20:01 schmunk42

Ah makes sense. While constructing the set of "all images being used by containers" we should append the :latest tag to any images that don't have tags, so that the set operations match correctly.

Or maybe using image ids instead would work.

dnephin avatar Jan 27 '16 01:01 dnephin

I think IDs would even be better, since there could be :1.0.0,:latest and none pointing to the same image.

schmunk42 avatar Jan 31 '16 21:01 schmunk42