fix(update): compare local image store IDs, not running container IDs

docker compose images -q reports the image IDs of currently running
containers, which don't change after a pull — so before == after always
and containers were never recreated.

Fix: resolve each service's image tag to its local SHA256 ID via
docker image inspect, which reads the local image store and correctly
reflects the newly pulled image. Falls back from 'config --images'
(compose v2.19+) to parsing 'config' yaml for older versions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-16 21:09:56 +02:00
parent fcff6f3298
commit 8ae9c9e878
+20 -2
View File
@@ -379,6 +379,24 @@ cmd_compose() {
# ─── Update Service ───────────────────────────────────────────────────────────
# Resolve each service's image tag to its current local SHA256 ID.
# Reads from the local image store (updated by 'docker compose pull'),
# NOT from running containers — so the comparison reflects the pulled image.
_stack_image_ids() {
local stack_dir="$1"; shift
local -a env_flag=("$@")
local images
# 'config --images' (compose v2.19+) outputs one image name per line;
# fall back to parsing the resolved config yaml for older versions.
if images=$(cd "$stack_dir" && docker compose "${env_flag[@]}" config --images 2>/dev/null) \
&& [[ -n "$images" ]]; then
echo "$images"
else
cd "$stack_dir" && docker compose "${env_flag[@]}" config 2>/dev/null \
| awk '/^\s+image:/{print $2}' | sort -u
fi | xargs -r docker image inspect --format '{{.Id}}' 2>/dev/null | sort
}
_update_run() {
load_root_env
@@ -398,9 +416,9 @@ _update_run() {
((checked++)) || true
local before after
before=$(cd "$stack_dir" && docker compose "${env_flag[@]}" images -q 2>/dev/null | sort || true)
before=$(_stack_image_ids "$stack_dir" "${env_flag[@]+"${env_flag[@]}"}")
(cd "$stack_dir" && docker compose "${env_flag[@]}" pull 2>&1) || true
after=$(cd "$stack_dir" && docker compose "${env_flag[@]}" images -q 2>/dev/null | sort || true)
after=$(_stack_image_ids "$stack_dir" "${env_flag[@]+"${env_flag[@]}"}")
if [[ "$before" != "$after" ]]; then
info " Updates found — recreating $stack"