Created
December 19, 2025 10:10
-
-
Save jhammann/c532014003a523269e8fcb72c87d96f4 to your computer and use it in GitHub Desktop.
Docker registry garbage collection with container start/stop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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