-
Notifications
You must be signed in to change notification settings - Fork 18.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to see when an image has last been used by a container #4237
Comments
Hi! If every one is ok with it #dibs |
I would start with a proposed design first to make sure people are ok with it. Wouldn't want you to waste your time coding stuff when people may not be ok with the idea in general. |
I was thinking to add the column "LAST UPDATED", "LAST USED" or similar to the "history" and "images" command, this field would be like the created one but will be updated when the image is created (import, build, pull...), a container runs/start and container stops Finally as @kencochrane said, it should update all the graph images (< none >:< none > too) with the new timestamp |
I'm thinking on witch actions should update the last_updated field, at first I'm thinking of:
Should be considered other actions like restart, kill...? what do you think? |
I would think a LastUsed field would only need to be updated upon container.create(). A value of nil would mean that, while its been pulled/downloaded, it has yet to be used by any container. |
Well, thinking as a graph and not only as a sngle image, when you pull an image that has as parent other image I think that the whole graph needs to be updated |
I agree the entire graph should "touched" upon container.create() |
I meant when you "create" an image (pull, build... ) |
@calavera can you please explain why this issue has been closed ? |
👍 for this feature, I also needed this today. Based on #20925 (comment) I believe the concern here is about keeping the Image data immutable. Whether we should have a mutable metadata struct for images, or if we should implement the feature with I'm reopening this issue, the usecase is more than relevant. |
This would be very useful, it would fix one of the pain points I hit with https://github.com/yelp/docker-custodian A section for daemon-local mutable meta data would have multiple uses, including #25728. |
Is somebody working on this? I'd like to give it a stab if it has been abandoned. From the comments:
Open to additional suggestions or warnings with some up to date info. Warnings in the sense of "because we now have docker swarm, LastUsed needs to be stored [...]". HMU |
@titpetric we're going to be releasing "data management" commands in docker 1.13; #26108 However this could still be useful if we want a @mlaventure wdyt? |
For garbage collection purposes, it may be best to define the filter as last in use. We should care less about the container.create() and more about the last time the image was active as a container (AKA when the last container of that image died). |
Will this ever be properly supported to see when an image was last in use? This is a huge problem with Docker containers in a CI environment where you run out of disk space and still want to preserve the mostly recently used containers. |
Same use case as @ryanwohara. Does anyone have any workarounds for this at the moment? Some external script that can keep track of last use dates? |
My docker-gc has some go code that does this. It watches events. |
I extract the events of last few days using this command
For my use case where I need to know given two versions of an image, whether the older version has been started within last few days. If it has not been started, then I remove it. |
@fs-sgujrati this will let you know last time it has been used to start a container, but you don't know how long this container has been running. Let's say you run a long-term service as docker container, you might consider image expired TTL while this container is still active (or maybe just recently stopped) so the actual "last use" of this image is way more recent |
With #31497 merged, there's the possibility to add additional information to images, without modifying the image's data itself; if someone wants to work on this, I can see that change being accepted; what's needed is a design (as in: when do we update the "last accessed" / "last used" date? Perhaps each time a container is created and/or a container that uses the image exits (or starts ?) - that looks like the tricky bit. |
You're right about the tricky part. API to give "last use" status for an image will need to know
I suggest new When new "last use" API is invoked, it computes |
This would be a nice feature. We are caching images to help reduce build times but we also would like to clean up redundant images which aren't used automatically via a cron job. |
Same Problem here in a CI enviroment - I would like to remove images where container start events are older than a couple of weeks. @fr-sgujrati Using docker events sounds promising but the event log only stores the last 1000 events so older start/destroy events gets lost. Or is it possible to increase the event log size in any way? Here's my PowerShell script:
|
@mawl I ended up using something else. My use case was that I had a container running on robot, which could periodically be updated. Due to this update, robot ended up having many older versions of the container. At a give point of time, the newest version will be in running state. If the newest version had any issues, then a previous stable version will be used. If a version is running fine for half day, it is safe to assume that other older (how old? described below) images will not be used and can be removed. I created a routine which periodically checks
It's not clean, but works for me. |
Using intermediate containers in builds also creates problems since
|
Note that, when using buildkit as a builder ( When using buildkit, the build cache can be pruned separately with
|
Was any progress made on this? I have the same CI clean up use case. |
I also have the same CI clean up use case. I created Docuum to address this problem. Like docker-gc, it watches events to learn when images are used. However, it makes some slightly different design choices. In particular:
Hope this is helpful. Contributions welcome. |
Cool!
Also I wasn’t smart enough to allow selecting storage on the fly in Go. I like your ideas though. I never thought this use it for my laptop. Sent with GitHawk |
In case it helps readers, https://github.com/Azure/eraser |
Has there been any progress in implementing a solution for this issue? |
@stepchowfun , I tried out Docuum, but I experienced it removing newly created images that were not yet used; which was problematic. UPDATE: Nvm, I think i just set limit too small. Relevant resolved issue: stepchowfun/docuum#137 |
Hi @tfreiling989, please file any Docuum-related bug reports against the Docuum repo. Thanks! |
Right now, it is hard to know when the last time an image was used by a container, so when you need to do some image cleanup, you have to either guess, or track that data outside of docker.
It would be nice if we add a new attribute for the
docker images
command that showed the last time the image was used, so that we can use that when running a image clean up job. Ideally the timestamp would follow the whole image hierarchy and not just the last image on the tree, but it's parents, grandparents, etc.I'm not sure when the image last_update is set, when the container is started, or stopped, but probably, best to update both times.
The text was updated successfully, but these errors were encountered: