From 30e7c2f6b0a1da5ee30c6ee958d10f42d4059840 Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Sun, 7 Jun 2026 09:57:00 -0400 Subject: [PATCH] Detect containers running behind already-pulled images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OLD_ID vs NEW_ID only caught updates landed during this run. If an image was pulled externally (Unraid UI), the container stayed on the old image while :latest moved on — this run saw nothing to do. Now also compare the container's current image ID against :latest and rebuild if behind. --- Docker_Essentials/docker_update.sh | 17 ++++++++++++----- Docker_Essentials/docker_update_remaining.sh | 13 +++++++++---- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Docker_Essentials/docker_update.sh b/Docker_Essentials/docker_update.sh index 5a6514e..25cd296 100755 --- a/Docker_Essentials/docker_update.sh +++ b/Docker_Essentials/docker_update.sh @@ -285,7 +285,10 @@ for container in "${TARGET_CONTAINERS[@]}"; do continue fi - # Capture image ID before pull to detect whether an update landed + # Capture the image ID the container is currently running on, and the + # image ID :latest points to before the pull. After pulling, we rebuild if + # either a new digest landed OR the container is behind what :latest is now. + CONTAINER_IMAGE_ID=$(docker inspect "$container" --format='{{.Image}}' 2>/dev/null || echo "") OLD_ID=$(docker image inspect "$IMAGE" --format='{{.Id}}' 2>/dev/null || echo "") log "$ICON_SYNC Pulling $IMAGE..." @@ -299,12 +302,16 @@ for container in "${TARGET_CONTAINERS[@]}"; do NEW_ID=$(docker image inspect "$IMAGE" --format='{{.Id}}' 2>/dev/null || echo "") if [[ $_pull_rc -eq 0 ]]; then - if [[ -n "$OLD_ID" ]] && [[ "$OLD_ID" != "$NEW_ID" ]]; then - log "$ICON_DONE $container — updated ✅ (${OLD_ID:7:12} → ${NEW_ID:7:12})" + _pull_new=$( [[ -n "$OLD_ID" && "$OLD_ID" != "$NEW_ID" ]] && echo true || echo false) + _container_behind=$([[ -n "$CONTAINER_IMAGE_ID" && -n "$NEW_ID" && "$CONTAINER_IMAGE_ID" != "$NEW_ID" ]] && echo true || echo false) + + if [[ "$_pull_new" == true || "$_container_behind" == true ]]; then + [[ "$_pull_new" == true ]] && log "$ICON_DONE $container — new image (${OLD_ID:7:12} → ${NEW_ID:7:12})" + [[ "$_container_behind" == true && "$_pull_new" == false ]] && log "$ICON_DONE $container — image already pulled, container behind (${CONTAINER_IMAGE_ID:7:12} → ${NEW_ID:7:12})" UPDATED+=("$container") - OLD_IMAGE_IDS+=("$OLD_ID") + OLD_IMAGE_IDS+=("$CONTAINER_IMAGE_ID") else - log "$container — already up to date (${NEW_ID:7:12})" + log "$container — up to date (${NEW_ID:7:12})" UP_TO_DATE+=("$container") fi else diff --git a/Docker_Essentials/docker_update_remaining.sh b/Docker_Essentials/docker_update_remaining.sh index cdefc66..5117b77 100755 --- a/Docker_Essentials/docker_update_remaining.sh +++ b/Docker_Essentials/docker_update_remaining.sh @@ -187,6 +187,7 @@ for container in "${REMAINING[@]}"; do continue fi + CONTAINER_IMAGE_ID=$(docker inspect "$container" --format='{{.Image}}' 2>/dev/null || echo "") OLD_ID=$(docker image inspect "$IMAGE" --format='{{.Id}}' 2>/dev/null || echo "") log "$ICON_SYNC Pulling $IMAGE..." @@ -200,12 +201,16 @@ for container in "${REMAINING[@]}"; do NEW_ID=$(docker image inspect "$IMAGE" --format='{{.Id}}' 2>/dev/null || echo "") if [[ $_pull_rc -eq 0 ]]; then - if [[ -n "$OLD_ID" ]] && [[ "$OLD_ID" != "$NEW_ID" ]]; then - log "$ICON_DONE $container — updated ✅ (${OLD_ID:7:12} → ${NEW_ID:7:12})" + _pull_new=$( [[ -n "$OLD_ID" && "$OLD_ID" != "$NEW_ID" ]] && echo true || echo false) + _container_behind=$([[ -n "$CONTAINER_IMAGE_ID" && -n "$NEW_ID" && "$CONTAINER_IMAGE_ID" != "$NEW_ID" ]] && echo true || echo false) + + if [[ "$_pull_new" == true || "$_container_behind" == true ]]; then + [[ "$_pull_new" == true ]] && log "$ICON_DONE $container — new image (${OLD_ID:7:12} → ${NEW_ID:7:12})" + [[ "$_container_behind" == true && "$_pull_new" == false ]] && log "$ICON_DONE $container — image already pulled, container behind (${CONTAINER_IMAGE_ID:7:12} → ${NEW_ID:7:12})" UPDATED+=("$container") - OLD_IMAGE_IDS+=("$OLD_ID") + OLD_IMAGE_IDS+=("$CONTAINER_IMAGE_ID") else - log "$container — already up to date (${NEW_ID:7:12})" + log "$container — up to date (${NEW_ID:7:12})" UP_TO_DATE+=("$container") fi else