Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded simple logic for dry run on prune containers #41449
Conversation
changed: daemon/prune.go TODO: Add tests Signed-off-by: Kaushik Varanasi <kaushik.varanasi1@gmail.com>
| @@ -26,6 +26,7 @@ var ( | |||
| "label": true, | |||
| "label!": true, | |||
| "until": true, | |||
| "dryRun": true, | |||
This comment has been minimized.
This comment has been minimized.
cpuguy83
Sep 14, 2020
Contributor
I would probably promote dryRun to a full option rather than a filter argument.
This comment has been minimized.
This comment has been minimized.
kaushik94
Sep 14, 2020
Author
@cpuguy83 when I remove this line, it is complaining me invalid parameters.
This comment has been minimized.
This comment has been minimized.
cpuguy83
Sep 14, 2020
Contributor
This is probably because you are passing dryRun as a filter rather than a configuration option.
It looks like we don't currently accept any options on prune other than filter.
This would need to be added at the API level.
This comment has been minimized.
This comment has been minimized.
kaushik94
Sep 14, 2020
Author
@cpuguy83 can you give an example of any top level options. Like --all? Can you show me the file to add this.
This comment has been minimized.
This comment has been minimized.
cpuguy83
Sep 14, 2020
Contributor
It will need to be decoded here:
moby/api/server/router/container/container_routes.go
Lines 713 to 728 in f416e99
The backend interface definition will need to be updated here:
The options will need to be encoded here:
moby/client/container_prune.go
Lines 13 to 36 in f416e99
| } | ||
| if cSize > 0 { | ||
| rep.SpaceReclaimed += uint64(cSize) | ||
| if (!dryRunMode) { |
This comment has been minimized.
This comment has been minimized.
cpuguy83
Sep 14, 2020
Contributor
This is duplicated in the else block.
I think this can be:
| if (!dryRunMode) { | |
| if !dryRunMode { | |
| if err := daemon.ContainerRm(c.ID, &types.ContainerRmConfig{}); err != nil { | |
| logrus.Warnf("failed to prune container %s: %v", c.ID, err) | |
| continue | |
| } | |
| } | |
| if cSize > 0 { | |
| rep.SpaceReclaimed += uint64(cSize) | |
| } | |
| rep.ContainersDeleted = append(rep.ContainersDeleted, c.ID) |
Note: Don't use GH's UI to accept the change, as the commit won't be signed and it will be rejected by CI.


kaushik94 commentedSep 14, 2020
•
edited
changed:
daemon/prune.go
TODO: Add tests
Signed-off-by: Kaushik Varanasi kaushik.varanasi1@gmail.com
- What I did
Implemented a simple dry run mode for containers
- How I did it
When checking for containers that are stale, moby does a
daemon.ContainerRm. In dry run mode, I simply disabled this line and returned the container id and size to be removed.- How to verify it
do
docker run hello-worlddocker containers prune --dry-runuse this branch for cli: docker/cli#2698
- Description for the changelog
changed:
daemon/prune.go
TODO: Add tests
- A picture of a cute animal (not mandatory but encouraged)
