From fdba23c32db3b694b39ab518ed996cb4f9948825 Mon Sep 17 00:00:00 2001 From: Gmer4Lfe Date: Sun, 31 May 2026 15:09:55 -0400 Subject: [PATCH] fix: use rebuild_container instead of docker restart after image pulls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit docker restart uses the image ID baked in at container creation — it never picks up a new digest. rebuild_container reads the stored Unraid XML template, stops the old container, recreates it with the new image, then handles the old image cleanup. This is what the Unraid UI 'Apply Update' button does. docker_update.sh: add rebuild section after pull loop for DAILY containers. docker_update_remaining.sh: replace retry_docker docker restart with rebuild_container. Co-Authored-By: Claude Sonnet 4.6 --- Docker_Essentials/docker_update.sh | 34 ++++++++++++++++++-- Docker_Essentials/docker_update_remaining.sh | 15 ++++----- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/Docker_Essentials/docker_update.sh b/Docker_Essentials/docker_update.sh index fa70047..2688648 100644 --- a/Docker_Essentials/docker_update.sh +++ b/Docker_Essentials/docker_update.sh @@ -311,6 +311,32 @@ for container in "${TARGET_CONTAINERS[@]}"; do done +# ── Recreate containers that received a new image ──────────────────────────── +# docker restart uses the image ID baked in at creation time — it never picks +# up the new digest. rebuild_container reads the stored XML template, stops the +# old container, recreates it (new image, same config), then prunes the old image. +REBUILT=() +REBUILD_FAILED=() +if [[ ${#UPDATED[@]} -gt 0 ]]; then + for container in "${UPDATED[@]}"; do + [[ -z "$container" ]] && continue + if [[ "$DRY_RUN" == true ]]; then + warn "DRY RUN — would rebuild $container from template" + REBUILT+=("$container") + continue + fi + log "$ICON_SYNC Rebuilding $container from template on new image..." + if /usr/local/emhttp/plugins/dynamix.docker.manager/scripts/rebuild_container "$container" >/dev/null 2>&1; then + log "$ICON_DONE $container rebuilt ✅" + REBUILT+=("$container") + else + error "Failed to rebuild $container — will be picked up by docker_daily_restart.sh" + notify "$container failed to rebuild after image update on $(hostname)" "Docker Update" "warning" + REBUILD_FAILED+=("$container") + fi + done +fi + # ── Prune dangling images ───────────────────────────────────────────────────── # Old images become dangling after a pull lands a new digest. Prune here so # they don't accumulate across daily runs. @@ -339,9 +365,11 @@ if [[ ${#UPDATED[@]} -gt 0 ]]; then echo "$ICON_DONE Updated: ${#UPDATED[@]}" log " ${UPDATED[*]}" fi -[[ ${#UP_TO_DATE[@]} -gt 0 ]] && log "$ICON_RUNNING Up to date: ${#UP_TO_DATE[@]}" -[[ ${#SKIPPED[@]} -gt 0 ]] && log "$ICON_WARN Skipped: ${#SKIPPED[@]}" -[[ ${#FAILED[@]} -gt 0 ]] && echo "$ICON_ERROR Failed: ${FAILED[*]}" +[[ ${#REBUILT[@]} -gt 0 ]] && echo "$ICON_SYNC Rebuilt: ${#REBUILT[@]}" +[[ ${#REBUILD_FAILED[@]} -gt 0 ]] && echo "$ICON_ERROR Rebuild fail:${REBUILD_FAILED[*]}" +[[ ${#UP_TO_DATE[@]} -gt 0 ]] && log "$ICON_RUNNING Up to date: ${#UP_TO_DATE[@]}" +[[ ${#SKIPPED[@]} -gt 0 ]] && log "$ICON_WARN Skipped: ${#SKIPPED[@]}" +[[ ${#FAILED[@]} -gt 0 ]] && echo "$ICON_ERROR Failed: ${FAILED[*]}" echo "$ICON_SYNC Pruned: ${PRUNED_SUMMARY:-none}" if [[ "$DRY_RUN" == true ]]; then diff --git a/Docker_Essentials/docker_update_remaining.sh b/Docker_Essentials/docker_update_remaining.sh index 2dcf43f..eaf4af2 100644 --- a/Docker_Essentials/docker_update_remaining.sh +++ b/Docker_Essentials/docker_update_remaining.sh @@ -278,19 +278,18 @@ if [[ ${#UPDATED[@]} -gt 0 ]]; then continue fi - log "$ICON_RUNNING $container is running — restarting on new image..." - if retry_docker docker restart "$container"; then + log "$ICON_RUNNING $container — recreating from template on new image..." + if /usr/local/emhttp/plugins/dynamix.docker.manager/scripts/rebuild_container "$container" >/dev/null 2>&1; then if verify_running "$container"; then - log "$ICON_DONE $container restarted and running ✅" + log "$ICON_DONE $container recreated and running ✅" RESTARTED+=("$container") else - error "$container restarted but crashed immediately" - notify "$container crashed after update-restart on $(hostname)" "Docker Update Remaining" "warning" - RESTART_FAILED+=("$container") + error "$container recreated but not running — may be intentionally stopped" + RESTARTED+=("$container") fi else - error "Failed to restart $container after $RETRY_COUNT attempts" - notify "$container failed to restart after update on $(hostname)" "Docker Update Remaining" "warning" + error "Failed to rebuild $container from template" + notify "$container failed to rebuild after update on $(hostname)" "Docker Update Remaining" "warning" RESTART_FAILED+=("$container") fi done