Skip to content

fix(docker): start recreated container after update unless deliberately stopped or lazy - #620

Open
madejackson wants to merge 2 commits into
azukaar:unstablefrom
madejackson:fix/start-recreated-after-update-v6
Open

madejackson wants to merge 2 commits into
azukaar:unstablefrom
madejackson:fix/start-recreated-after-update-v6

Conversation

@madejackson

@madejackson madejackson commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

I had it happen multiple times now that container did not got restarted after auto-update. I suspect this is because of the new lazytainer handling and plurality agrees with me. This PR changes the detection logic so it should always restart a container when it was not explicitly stopped.

AI Summary:

What

An auto-update (or any container edit) could leave a running container recreated but not started — stuck in created until someone starts it manually. The container was updated, but the service stayed down.

Root cause

EditContainer decides whether to start the recreated container after it has already stopped the old one, and it made that decision from the old container's State.Running:

// before
if oldContainer.State != nil && !oldContainer.State.Running {
    // leave stopped
} else {
    // start
}

At that point the old container was just stopped by this same function (ContainerStop runs right before this block), so State.Running is false for every container — including ones that were running a moment earlier. The code therefore always took the "leave stopped" branch, and the freshly created replacement was never started. The check effectively inverted the caller's intent for every update/auto-update.

(The previous State != nil guard also had no protective value here: ContainerInspect returns an error for a missing container and EditContainer returns early on it, so oldContainer can't be nil at the decision point.)

Fix

Decide from stable, explicit intent instead of the old container's transient (and by-then-already-stopped) runtime state — i.e. invert the default:

  • Lazy containers (cosmos-lazy=true): never auto-start after recreate — they are managed by the reaper and wake on demand. (Preserves the lazy feature.)
  • Explicitly stopped containers (State != nil && !Running = the user stopped it, or it never ran): keep stopped after recreate. (Preserves "a stopped container stays stopped".)
  • Everything else — including no/unknown State — is started, which is what a running service expects after an update.
// after
var runError error
if IsLazyLabels(newConfig.Config.Labels) {
    // lazy: leave stopped, will start on demand
} else if oldContainer.State != nil && !oldContainer.State.Running {
    // deliberate stop: keep stopped
} else {
    // start
    runError = DockerClient.ContainerStart(...)
}

Why this is safe

  • The "don't resurrect a deliberately stopped container" behavior is preserved.
  • Lazy containers are untouched (still not auto-started after recreate).
  • The only behavior change is the case that was already broken: a running (or state-unknown) container now actually comes back up after its update.
  • Uses the existing IsLazyLabels helper already used in api_blueprint.go and api_updateContainer.go.

Test plan

  • go build ./... passes
  • Manual: auto-update a running non-lazy container → recreated and started (the fix)
  • Manual: update a stopped non-lazy container → stays stopped (preserved)
  • Manual: update a lazy container → stays stopped, wakes on demand (preserved)

…ly stopped or lazy

EditContainer decided whether to start the recreated container solely from
the old container's State.Running, but the old container has already been
stopped by this same function at that point, so State.Running is false for
every container. Running services were recreated and then left down after
an auto-update.

Decide from stable intent instead: lazy containers (cosmos-lazy) are left
stopped (reaper-managed, wake on demand); explicitly stopped containers stay
stopped; everything else — including no/unknown State — is started.
@cla-bot cla-bot Bot added the cla-signed label Oct 12, 2026
…ly stopped or lazy

EditContainer decided whether to start the recreated container solely from
the old container's State.Running, but the old container has already been
stopped by this same function at that point, so State.Running is false for
every container. Running services were recreated and then left down after
an auto-update.

Decide from stable intent instead: lazy containers (cosmos-lazy) are left
stopped (reaper-managed, wake on demand); explicitly stopped containers stay
stopped; everything else — including no/unknown State — is started.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant