fix: use rebuild_container instead of docker restart after image pulls
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
55a38b6b74
commit
fdba23c32d
@@ -311,6 +311,32 @@ for container in "${TARGET_CONTAINERS[@]}"; do
|
|||||||
|
|
||||||
done
|
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 ─────────────────────────────────────────────────────
|
# ── Prune dangling images ─────────────────────────────────────────────────────
|
||||||
# Old images become dangling after a pull lands a new digest. Prune here so
|
# Old images become dangling after a pull lands a new digest. Prune here so
|
||||||
# they don't accumulate across daily runs.
|
# they don't accumulate across daily runs.
|
||||||
@@ -339,9 +365,11 @@ if [[ ${#UPDATED[@]} -gt 0 ]]; then
|
|||||||
echo "$ICON_DONE Updated: ${#UPDATED[@]}"
|
echo "$ICON_DONE Updated: ${#UPDATED[@]}"
|
||||||
log " ${UPDATED[*]}"
|
log " ${UPDATED[*]}"
|
||||||
fi
|
fi
|
||||||
[[ ${#UP_TO_DATE[@]} -gt 0 ]] && log "$ICON_RUNNING Up to date: ${#UP_TO_DATE[@]}"
|
[[ ${#REBUILT[@]} -gt 0 ]] && echo "$ICON_SYNC Rebuilt: ${#REBUILT[@]}"
|
||||||
[[ ${#SKIPPED[@]} -gt 0 ]] && log "$ICON_WARN Skipped: ${#SKIPPED[@]}"
|
[[ ${#REBUILD_FAILED[@]} -gt 0 ]] && echo "$ICON_ERROR Rebuild fail:${REBUILD_FAILED[*]}"
|
||||||
[[ ${#FAILED[@]} -gt 0 ]] && echo "$ICON_ERROR Failed: ${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}"
|
echo "$ICON_SYNC Pruned: ${PRUNED_SUMMARY:-none}"
|
||||||
|
|
||||||
if [[ "$DRY_RUN" == true ]]; then
|
if [[ "$DRY_RUN" == true ]]; then
|
||||||
|
|||||||
@@ -278,19 +278,18 @@ if [[ ${#UPDATED[@]} -gt 0 ]]; then
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "$ICON_RUNNING $container is running — restarting on new image..."
|
log "$ICON_RUNNING $container — recreating from template on new image..."
|
||||||
if retry_docker docker restart "$container"; then
|
if /usr/local/emhttp/plugins/dynamix.docker.manager/scripts/rebuild_container "$container" >/dev/null 2>&1; then
|
||||||
if verify_running "$container"; then
|
if verify_running "$container"; then
|
||||||
log "$ICON_DONE $container restarted and running ✅"
|
log "$ICON_DONE $container recreated and running ✅"
|
||||||
RESTARTED+=("$container")
|
RESTARTED+=("$container")
|
||||||
else
|
else
|
||||||
error "$container restarted but crashed immediately"
|
error "$container recreated but not running — may be intentionally stopped"
|
||||||
notify "$container crashed after update-restart on $(hostname)" "Docker Update Remaining" "warning"
|
RESTARTED+=("$container")
|
||||||
RESTART_FAILED+=("$container")
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
error "Failed to restart $container after $RETRY_COUNT attempts"
|
error "Failed to rebuild $container from template"
|
||||||
notify "$container failed to restart after update on $(hostname)" "Docker Update Remaining" "warning"
|
notify "$container failed to rebuild after update on $(hostname)" "Docker Update Remaining" "warning"
|
||||||
RESTART_FAILED+=("$container")
|
RESTART_FAILED+=("$container")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user