Repository navigation
Conversation
When a container is recreated (Watchtower, docker-compose up -d, ...), the monitor keeps a handle for the old container id, so every poll fails with 'DockerError 404' forever and retries every 60s. If the destroy event is missed (docker proxy, races), a later create event bails out with 'Container already monitored' without replacing the stale monitor. - On 404, try to re-attach to a container with the same name; on success the monitor continues with the fresh handle. - If the container does not exist anymore (2 consecutive 404s), ask the DockerAPI instance to drop this monitor so a later create event can re-add it. - _container_add now replaces a stale monitor instead of returning early. Fixes ualex73#188
ak111pro
added a commit
to ak111pro/monitor_docker
that referenced
this pull request
Oct 19, 2026
A failed attach in _container_add left the monitor in the container table, so every later container of that name was skipped as "Container already monitored" and never monitored (ualex73#166). The monitor is dropped now, and a container that vanished before it could be attached is logged as a warning instead of an error. When a monitored container was recreated and the destroy event was missed, the poll loop retried the old container id forever (ualex73#188). On a 404 the monitor now re-attaches to the container that has its name; if there is none twice in a row it asks DockerAPI to drop the monitor and its entities, and the next create event adds it back. A create event for a name whose monitor points to an old container replaces that monitor. Approach from ualex73#219 by @ciltocruz, adapted to the selection-aware monitors (callback instead of a parent reference, monitor identity checks, counters reset after re-attaching). Co-authored-by: ciltocruz <19903919+ciltocruz@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015BTTm7J9zaAQxmzuzViueF
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #188
Problem
When a container is recreated (Watchtower,
docker-compose up -d, podman restart, ...), each monitor keeps the Docker API handle for the old container id. The new container has the same name but a new id, so:Container not available anymore (3a) (DockerError 404 ...)every retry, forever, and never recovers (worst case through docker-proxy where events can be missed).destroyevent is missed, the latercreateevent hitsContainer already monitoredand is dropped, so the stale monitor is never replaced.Also seen with podman: a stopped then restarted container stays
unknownuntil HA is restarted.Fix (
custom_components/monitor_docker/helpers.py)DockerError 404in the container poll loop, try to re-attach by name (_handle_container_gone). If the recreated container is found, monitoring continues transparently with the fresh handle (Re-attached to recreated container).DockerAPIinstance to drop its own monitor (on_container_gone), so entities are removed and a latercreateevent re-adds everything cleanly._container_addnow detects the name is monitored, checks the new container's id, and replaces the stale monitor instead of bailing out withContainer already monitored.Behavior notes
load_platformflow when a monitor is re-added.