Podman’s prune command is more like a selective demolition crew than a general cleanup, and understanding its nuances can save you from accidentally deleting something crucial.

Let’s see it in action. Imagine you’ve been experimenting, pulling images and spinning up containers that you no longer need.

# List all containers, including stopped ones
podman ps -a

# List all images
podman images

# List all volumes
podman volume ls

You’ll likely see a bunch of entries you want to get rid of.

The core problem podman prune addresses is the accumulation of "dangling" or unused resources within Podman. These are artifacts left behind after containers are removed or images are updated, taking up disk space and cluttering your view.

Podman offers several prune commands, each targeting a specific resource type:

  • podman container prune: Removes stopped containers.
  • podman image prune: Removes dangling images (images not tagged and not used by any container).
  • podman volume prune: Removes unused volumes.
  • podman network prune: Removes unused networks.
  • podman system prune: A comprehensive cleanup, removing stopped containers, dangling images, unused networks, and build cache.

Let’s focus on podman image prune as an example. When you build a new version of an image, the old version might become "dangling" if it’s not tagged and no running or stopped container is using it. podman image prune is designed to sweep these up.

Here’s a typical workflow:

  1. Identify what will be pruned: Before deleting anything, it’s wise to see what prune would remove. This is done using the -f (or --filter) flag with a value of dangling=true.

    podman image prune -f dangling=true
    

    This command will list all dangling images that would be removed.

  2. Perform the prune: Once you’re confident, execute the prune command without the filter, or with the -a flag to remove all unused images (not just dangling ones).

    podman image prune
    

    This command will prompt for confirmation before deleting. To bypass the prompt, use the -f flag.

    podman image prune -f
    

The mental model for prune is about resource lifecycle management. Podman, like other container runtimes, creates resources (containers, images, volumes, networks) and these resources have a lifecycle. When a container is stopped, it’s not necessarily deleted; it’s just in a stopped state. Similarly, when you build a new image, the old one might still be around. prune commands are the tools to clean up the end-of-life or unused resources.

The podman system prune command is the most aggressive, acting as a catch-all. It’s often used when you want to reclaim significant disk space quickly.

podman system prune -f

This will remove:

  • All stopped containers.
  • All dangling images.
  • All unused networks.
  • All build cache.

It’s crucial to understand that podman image prune by default only removes dangling images. If an image is tagged but not used by any container, it will not be removed by podman image prune alone. To remove all images that are not associated with any container (running or stopped), you need to use a filter:

podman image prune --filter "until=0h" -f

This specific filter until=0h combined with -f effectively tells Podman to remove all images that haven’t been used in the last 0 hours, which translates to any image not currently referenced by a container. This is a common point of confusion, as people often expect podman image prune to clean up all unreferenced images without additional flags.

After running podman system prune -f, the next logical step for comprehensive cleanup might involve addressing unused volumes, which are not removed by system prune by default.

Want structured learning?

Take the full Podman course →