mirror of
https://github.com/moby/moby.git
synced 2025-07-29 07:21:35 +03:00
Add --filter until=<timestamp>
for docker container/image prune
This fix is a follow up for comment https://github.com/docker/docker/pull/28535#issuecomment-263215225 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 #28497. This fix is related to #28535. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@ -5,6 +5,7 @@ package main
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/integration-cli/checker"
|
||||
"github.com/docker/docker/integration-cli/daemon"
|
||||
@ -90,3 +91,23 @@ func (s *DockerDaemonSuite) TestPruneImageDangling(c *check.C) {
|
||||
c.Assert(err, checker.IsNil)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id)
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestPruneContainerUntil(c *check.C) {
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox")
|
||||
id1 := strings.TrimSpace(out)
|
||||
c.Assert(waitExited(id1, 5*time.Second), checker.IsNil)
|
||||
|
||||
until := daemonUnixTime(c)
|
||||
|
||||
out, _ = dockerCmd(c, "run", "-d", "busybox")
|
||||
id2 := strings.TrimSpace(out)
|
||||
c.Assert(waitExited(id2, 5*time.Second), checker.IsNil)
|
||||
|
||||
out, _ = dockerCmd(c, "container", "prune", "--force", "--filter", "until="+until)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id2)
|
||||
|
||||
out, _ = dockerCmd(c, "ps", "-a", "-q", "--no-trunc")
|
||||
c.Assert(strings.TrimSpace(out), checker.Not(checker.Contains), id1)
|
||||
c.Assert(strings.TrimSpace(out), checker.Contains, id2)
|
||||
}
|
||||
|
Reference in New Issue
Block a user