apple / apple/container

[Request]: Storage - Add `container system prune` command to remove unused resources

Open
#891 6 comments 9 reactions 0 assignees View on GitHub
storage
Dominant language
Swift
Stars
49.9k
Forks
1.8k
Avg merge
1d 20h
Merged PRs (30d)
22

Description

### Feature or enhancement request details

Add a container system prune subcommand to remove unused images, stopped containers, and dangling volumes in a single operation. This provides a convenient way for users to reclaim disk space.

Some basic requirements:
- Remove all stopped containers
- Remove dangling images (untagged and not referenced by any container)
- Remove unused volumes (not mounted by any container)
- Support --all flag to remove all unused images (not just dangling)
- Support --volumes flag to include volume cleanup
- Show what will be deleted and prompt for confirmation (unless --force is used)
- Automatically trigger fstrim after cleanup to actually reclaim disk space (related - https://github.com/apple/containerization/issues/414)

Example usage:

```
container system prune # Remove stopped containers and dangling images
container system prune --all # Remove all unused images
container system prune --volumes --force # Include volumes, skip confirmation
```

Example output:
```
Pruned containers:
abc123def456
789ghi012jkl

Pruned images:
sha256:abcd1234...
sha256:efgh5678...

Reclaimed 8.5GB in disk space
```

Some things to discuss
- Filter options (e.g., --filter "until=24h" to prune resources older than 24h)
- Whether to automatically run fstrim inline vs. async (See https://github.com/apple/containerization/issues/414)
- Dry-run mode to preview what would be deleted

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the existing `container system` command structure and resource cleanup behavior; the issue does not name files or tests. Clarify filtering, dry-run behavior, confirmation, and inline versus asynchronous fstrim before implementing. Done means the command removes the specified resources, supports `--all`, `--volumes`, and `--force`, reports deletions and reclaimed space, and triggers fstrim.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.