Skip to content

Instantly share code, notes, and snippets.

@gchait
Created December 13, 2025 12:22
Show Gist options
  • Select an option

  • Save gchait/7505e8d6ecefb4852ab33d38f1c29a5e to your computer and use it in GitHub Desktop.

Select an option

Save gchait/7505e8d6ecefb4852ab33d38f1c29a5e to your computer and use it in GitHub Desktop.
Keep only a specific tag from a Docker repository
# shellcheck disable=SC2086
docker images -q "${DOCKER_REPO_FULL}" | \
grep -v "$(docker images -q ${DOCKER_IMAGE})" | \
xargs --no-run-if-empty docker rmi -f
@gchait
Copy link
Author

gchait commented Dec 13, 2025

For latest:

docker images xxx/yyy --format "{{.CreatedAt}}\t{{.Repository}}:{{.Tag}}" | \
  sort -r | tail -n +2 | cut -f2 | xargs --no-run-if-empty docker rmi

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