Add --filter until=<timestamp> for docker container/image prune#29226
Add --filter until=<timestamp> for docker container/image prune#29226thaJeztah merged 1 commit intomoby:masterfrom
--filter until=<timestamp> for docker container/image prune#29226Conversation
There was a problem hiding this comment.
Can you clarify the format of <timestamp> in docs?
There was a problem hiding this comment.
Thanks @AkihiroSuda. The docs has been updated.
There was a problem hiding this comment.
Can we have a test for --until=5s? (IMO we should allow some suffix like "ago". i. e. support --until="5s ago" as well)
See also: https://github.com/docker/docker/blob/master/api/types/time/timestamp_test.go
There was a problem hiding this comment.
Added a test for --filter until=3s.
I am thinking for adding ago, this could be a separate PR because --filter until=<timestamp> always use the same format as --since and --until. Changing the format will have an impact on other parts of the code base as well.
cli/command/system/prune.go
Outdated
There was a problem hiding this comment.
Can you support volumes and networks as well?
There was a problem hiding this comment.
Thanks. networks has been added. Currently volumes does not have a timestamp so it is not implemented.
There was a problem hiding this comment.
images -> images/containers ?
There was a problem hiding this comment.
Please clarify that filter is not supported for volumes and networks? (If you are facing a difficulty in supporting them)
There was a problem hiding this comment.
Networks have been added. Volumes needs a timestamp which is not there yet.
daemon/prune.go
Outdated
There was a problem hiding this comment.
The code seems copy-pasted from ContainersPrune(). Let's dedup it.
8df8f9f to
5a28853
Compare
|
Thanks @AkihiroSuda for the review. The PR has been updated. Please take a look. |
|
Thank you for updating this PR, almost looks good, however I still wonder some people feel |
mlaventure
left a comment
There was a problem hiding this comment.
Only a nit regarding the code.
I haven't yet read the doc part.
cli/command/system/prune.go
Outdated
There was a problem hiding this comment.
Should probable be e.g. instead of i.e. since there's going to be other filters included eventually (would prevent forgetting changing the text here)
The same applies for the other prune commands
5a28853 to
9fc49f3
Compare
|
Thanks @mlaventure. The help output in code and docs has been updated. Please take a look. |
|
LGTM I agree that If that works for @AkihiroSuda, I think we can move this to doc-reviews |
vdemeester
left a comment
There was a problem hiding this comment.
Wouldn't it make more sense to have :
# all images/containers created before 10m ago
--filter until=10m
# all images/container created before that date
--filter before=2017-01-01 # <- a valid timestamp/cc @thaJeztah @dnephin
There was a problem hiding this comment.
If you rebase, you should be able to do s.d.StartWithBusybox(c) without the Assert.
9fc49f3 to
806ad6f
Compare
|
moving back to design review given it seems we still haven't agreed on the input format 😅 |
|
We should have a look if changes are needed; I noticed that If we have the same for this option, that would be consistent, and easy to use |
|
Actually, I see it was described in this PR 😄 So I think @vdemeester's comment is addressed? |
|
Moving to docs-review, /cc @thaJeztah 👼 |
thaJeztah
left a comment
There was a problem hiding this comment.
left some suggestions, and a question 😄
api/swagger.yaml
Outdated
There was a problem hiding this comment.
Perhaps we should use <timestamp> here as well, and explain the format? Does the API take the Go format, or is this a numeric (UNIX) timestamp?
There was a problem hiding this comment.
Thanks @thaJeztah. The swagger.yaml has been updated. The API takes the same format (Go, timestamp) as the cli.
api/swagger.yaml
Outdated
There was a problem hiding this comment.
Thanks. Done. Also updated the part for /networks/prune (missed that one before).
There was a problem hiding this comment.
I think images should be containers here?
There was a problem hiding this comment.
Also, instead of "filter", describe what the result is; "only remove containers created before given timestamp"
There was a problem hiding this comment.
I think we can use one or two examples here;
- an example showing a duration string "The following example prunes all stopped containers that were created more than 30 minutes ago"
- an example showing an absolute date/time
- we may have to emphasize that it's looking at the creation time, not the time that the container was stopped / exited (thinking of this, I think that would actually be more useful; i.e., as a user, I may want to keep containers around that were created 10 months ago, but exited 10 minutes ago. When cleaning up containers, it's more likely I'm no longer interested in a container that exited 2 weeks ago). <-- @vdemeester WDYT?
There was a problem hiding this comment.
hum good point, this is trickier than I though at first… I also think FinishedTime (the time the contanier stopped) makes sense, but I think prune could also be used to clean running containers right ?
There was a problem hiding this comment.
Don't think it does;
Usage: docker container prune [OPTIONS]
Remove all stopped containers
Options:
-f, --force Do not prompt for confirmation
--help Print usage
There was a problem hiding this comment.
@thaJeztah @vdemeester The docs have been updated with several examples. Please take a look.
On a separate note, I agree it probably would be more useful for containers to use "stopped/exited" time.
The only downside is that, the stopped/exited time will only be appropriate for containers. For images or networks, we will not keep records for "deleted images" or "deleted networks". So there might be some inconsistency if we use stopped/exited time for containers while at the same time use created time for images or networks.
For that I think it might make sense to keep until as created time across the board (containers, images, networks), and have another filter for stopped/exited time on containers.
Maybe something like finished_before or running_until?
I can created a separate PR if this is preferable.
There was a problem hiding this comment.
@thaJeztah @vdemeester The docs have been updated with several examples. Please take a look.
On a separate note, I agree it probably would be more useful for containers to use "stopped/exited" time.
The only downside is that, the
stopped/exitedtime will only be appropriate for containers. For images or networks, we will not keep records for "deleted images" or "deleted networks". So there might be some inconsistency if we usestopped/exitedtime for containers while at the same time usecreatedtime for images or networks.For that I think it might make sense to keep
untilascreatedtime across the board (containers, images, networks), and have another filter forstopped/exitedtime on containers.Maybe something like
finished_beforeorrunning_until?
last_use?
This could be defined for images, containers and networks.
- container: last time the containers was running (i.e. last time the container stopped).
- image: last time a container based on this image was running.
- network: last time it had a running container in it.
I can created a separate PR if this is preferable.
Did you ever create this PR?
There was a problem hiding this comment.
There's this tracking issue to keep track when an image was last "used"; #4237
There was a problem hiding this comment.
Can you add one or two simple examples here as well (and explain what they do?)
There was a problem hiding this comment.
Can you add some simple examples here as well?
There was a problem hiding this comment.
Perhaps, instead of "filter", describe what the result is; "only remove images created before given timestamp"
There was a problem hiding this comment.
"only remove containers, images, and networks created before given timestamp"
This fix is a follow up for comment moby#28535 (comment) This fix provides `--filter until=<timestamp>` for `docker container/image prune`. This fix adds `--filter until=<timestamp>` to `docker container/image prune` so that it is possible to specify a timestamp and prune those containers/images that are earlier than the timestamp. Related docs has been updated Several integration tests have been added to cover changes. This fix fixes moby#28497. This fix is related to moby#28535. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
619aaa6 to
58738cd
Compare
|
all green |
Add `--filter until=<timestamp>` for `docker container/image prune`
Add `--filter until=<timestamp>` for `docker container/image prune`
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com> (cherry picked from commit bd33a99) Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com> Conflicts: - daemon/prune.go: missing moby#29226, moby#29963
- What I did
This fix is a follow up for comment
#28535 (comment)
This fix provides
--filter until=<timestamp>fordocker container/image prune.- How I did it
This fix adds
--filter until=<timestamp>todocker container/image pruneso that it is possible to specify a timestamp and prune those containers/images that are earlier than the timestamp.Related docs has been updated.
- How to verify it
Several integration tests have been added to cover changes.
- Description for the changelog
Add
--filter until=<timestamp>fordocker container/image prune- A picture of a cute animal (not mandatory but encouraged)
This fix fixes #28497.
This fix is related to #28535.
Signed-off-by: Yong Tang yong.tang.github@outlook.com