Managing storage - old containers

Hi,

What is the correct way to clean old container images and volumes on CoreOS?

podman system prune --all --volumes in a systemd timer?

I just freed 48GiB.

Yeah. There might be a better way, but timers seem like a good approach. For our builders we’re using a timer: https://github.com/coreos/fedora-coreos-pipeline/blob/aa70ee8148c94c39b2fbd8571653c5f604f2cbae/multi-arch-builders/builder-common.bu#L75-L104

    - path: /home/builder/.config/systemd/user/prune-container-resources.service
      mode: 0644
      user:
        name: builder
      group:
        name: builder
      contents:
        inline: |
          [Unit]
          Description=Prune Dangling and Expired Container Resources
          [Service]
          Type=oneshot
          ExecStart=podman image prune --force
          ExecStart=podman image prune --all --force --filter until=48h
          ExecStart=podman container prune --force
          ExecStart=podman volume prune --force --filter="label!=persistent"
    - path: /home/builder/.config/systemd/user/prune-container-resources.timer
      mode: 0644
      user:
        name: builder
      group:
        name: builder
      contents:
        inline: |
            [Timer]
            OnCalendar=*-*-* 05:00:00 UTC
            AccuracySec=30m
            Persistent=true
            [Install]
            WantedBy=timers.target

This example is specific to our needs but here is what it does:

  • podman image prune --force
    • prune all dangling images
  • podman image prune --all --force --filter until=48h
    • prune all images (even non dangling ones) after they are 48h old
  • podman container prune --force
    • prune any non running containers
  • podman volume prune --force --filter="label!=persistent"
    • prune any volumes that aren’t attached and don’t have the persistent label
1 Like