Skip to content

podman container prune: add --external support #30030

Open

Description

@c4rt0

Feature request: podman container prune --external

Target repo: podman-container-tools/podman (moved from containers/podman)
Status: Not filed yet

Problem

Build containers created by podman build / buildah ("external" containers,
shown by podman ps --external with command buildah and status Storage)
can be left behind when a build fails or is interrupted. There is no built-in
age-based cleanup that can reliably distinguish abandoned external build
containers from active ones:

  • podman container prune does not see external containers.

  • podman system prune --build removes build containers without an age filter
    and is documented as unsafe while builds are in progress.

  • podman image prune --all --external --filter until=48h (the command our
    prune timer ran) cannot be used either. --all includes tagged images,
    until=48h selects images by their creation date, not the container's,
    and --external allows pruning images that external containers still use.
    In our case it removed a pulled base image that was more than 48h old while
    a build was using it, and that build's container was deleted with it. The
    build failed with:

    error deleting build container "...": identifier is not a container
    

Proposal

Add --external to podman container prune, honouring --filter until= on
the container's own creation time:

podman container prune --external --force --filter until=24h

An age filter alone is only a heuristic: a build that runs longer than the
threshold could still be removed. The command should ideally skip external
containers used by active builds. It is unclear whether Podman can reliably
identify that state; if it cannot, the command would remain a policy-based
cleanup rather than a guarantee that active builds are safe.

Workaround (tested in isolated storage, podman 5.8.4)

podman ps --external --filter until=24h --filter command=buildah \
  --format '{{.ID}}' | xargs --no-run-if-empty podman rm --force

podman ps --external applies until to the container's own age (tested on
podman 5.8.4).

Context

Came out of the builder prune timer fix in fedora-coreos-pipeline PR 1410,
where the review suggested filing this upstream. Once Podman supports it
natively, the workaround in prune-container-resources.sh could be replaced
with podman container prune --external --force --filter until=24h, subject to
the active-build safety limitation above.

Prior related report: #14523
describes an interrupted build leaving a hard-to-remove build container
(Podman 4.1.0).

Filing template

URL: https://github.com/podman-container-tools/podman/issues/new?template=feature_request.yaml

Title:

podman container prune: support external (buildah) containers

The form has four fields. Paste each block into its field.

Feature request description:

Build containers created by `podman build` (external containers: command
`buildah`, status `Storage` in `podman ps --external`) are left behind when a
build fails or is interrupted. There is no built-in age-based cleanup that can
reliably distinguish abandoned external build containers from active ones:

- `podman container prune` does not see external containers.
- `podman system prune --build` removes build containers without an age filter
  and is documented as unsafe while builds are in progress.
- `podman image prune --all --external --filter until=48h` is not a fit
  either: `--all` includes tagged images, `until=48h` selects images by their
  creation date, and `--external` allows pruning images that external
  containers still use. In our case it removed a pulled base image older
  than 48h while a build was using it, and the running build's
  container was deleted with it. The build failed with:

      error deleting build container "...": identifier is not a container

We hit this on build hosts that run a periodic prune timer.

Suggest potential solution:

Support `--external` in `podman container prune`, applying
`--filter until=` to the container's own creation time:

    podman container prune --external --force --filter until=24h

An age threshold alone is only a heuristic: a build that runs longer than the
threshold could still be removed. Ideally the command would skip external
containers used by active builds. If Podman cannot reliably identify that
state, please clarify the limitation and intended safety model.

Have you considered any alternatives?:

Current workaround:

    podman ps --external --filter until=24h --filter command=buildah \
      --format '{{.ID}}' | xargs --no-run-if-empty podman rm --force

`podman ps --external` honours `until` on the container's age (tested on
Podman 5.8.4). `podman system prune --build` and
`image prune --all --external` are not suitable for this, for the reasons
above. The age cutoff is still a heuristic and does not guarantee that a
selected container is abandoned.

Additional context:

Podman 5.8.4. Downstream fix: https://github.com/coreos/fedora-coreos-pipeline/pull/1410
Prior related report: https://github.com/podman-container-tools/podman/issues/14523
Drafted with AI assistance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions