Skip to content

Instantly share code, notes, and snippets.

@jhammann
Created December 19, 2025 10:10
Show Gist options
  • Select an option

  • Save jhammann/c532014003a523269e8fcb72c87d96f4 to your computer and use it in GitHub Desktop.

Select an option

Save jhammann/c532014003a523269e8fcb72c87d96f4 to your computer and use it in GitHub Desktop.
Docker registry garbage collection with container start/stop
#!/bin/sh
# registry-gc.sh
# Stop registry -> run GC -> start registry (safe for docker distribution registry)
set -eu
COMPOSE_DIR="/path/to/compose"
SERVICE="registry"
CONFIG_IN_CONTAINER="/etc/docker/registry/config.yml"
LOG_FILE="/var/log/registry-gc.log"
cd "$COMPOSE_DIR"
ts() { date "+%Y-%m-%d %H:%M:%S"; }
{
echo "[$(ts)] Starting registry GC"
echo "[$(ts)] Stopping ${SERVICE}"
docker-compose stop "$SERVICE"
echo "[$(ts)] Running garbage-collect"
docker-compose run --rm "$SERVICE" registry garbage-collect "$CONFIG_IN_CONTAINER"
echo "[$(ts)] Starting ${SERVICE}"
docker-compose start "$SERVICE"
echo "[$(ts)] Done"
} >>"$LOG_FILE" 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment