Skip to content

Instantly share code, notes, and snippets.

@janhicken
Created October 29, 2024 07:59
Show Gist options
  • Save janhicken/c8bef536e1f58216dcb69eabf34b8297 to your computer and use it in GitHub Desktop.
Save janhicken/c8bef536e1f58216dcb69eabf34b8297 to your computer and use it in GitHub Desktop.
Script to clean up disk usage of Docker daemon artifacts: dangling images, container structure test, volumes
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
filters=(
'dangling=true'
'reference=registry.structure_test.oci.local/image:*'
'reference=cst.oci.local/*'
)
for arg in "$@"; do
filters+=("reference=$arg")
done
{
for filter in "${filters[@]}"; do
docker images --filter="$filter" --format='{{.ID}}'
done
} | sort --unique | xargs -r docker image remove --force
docker volume prune --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment