Skip to content

Epic: run stop, restart and down through the reconciliation plan #14551

Todo

Description

@ndeloof

Summary

up, create, start and scale go through the reconciliation plan (reconcile.go → executor.go). stop, restart and down do not: they still walk the services with InReverseDependencyOrder / InDependencyOrder and run their own copy of the logic. This epic tracks moving them onto the plan, one reviewable PR at a time. It follows #14081, which did the same for the start phase.

The two engines already disagree on user-visible behavior. Checked on current main, with a service that has a pre_stop hook writing to a volume:

Operation Engine pre_stop hook ran
up that recreates the container plan no
up --scale web=2, then web=1 plan no
restart dependency walk yes
down dependency walk yes

The plan stops containers with a bare ContainerStop (execStopContainer); hooks only exist in the code of down and restart.

Why

  • One behavior per concern: a fix to stopping, hooks, timeouts or removal tolerance lands once. down.go alone is 660 lines and one of the most patched files.
  • The plan is data. Once every lifecycle operation is a plan, it can be published to a progress display (see feat(display): draw the progress of up and down from a status #14544), inspected with --dry-run, and computed or executed by something other than the CLI process without a second implementation.

Scope

In: stop, restart, down. start and scale are already on the plan. Not in this epic: run (it creates its container directly), build, and the one-shot container commands (kill, pause, exec...).

Sub-tasks

  • Run pre_stop hooks as a plan operation, before every plan stop. Fixes the table above (up recreate, scale down) and is useful on its own.
  • Lock the current behavior of stop, restart and down with e2e scenarios before touching them: -p name down without the compose file, --remove-orphans, -v, --rmi, services disabled by a profile, already stopped containers, restart with dependents and restart: true edges, partial failure.
  • stop on the plan. A target state per resource (running, stopped, removed) in the reconciler; a scope for it; the provider stop action; services selected without their dependents.
  • restart on the plan. A restart operation (atomic ContainerRestart or stop + start, to decide); dependency order with the existing wait nodes; only restart: true edges; hooks around it.
  • down on the plan. Containers in reverse dependency order, orphans, pre_start hook containers, networks, volumes, images, jobs; tolerant removals ("already gone", "still in use" as warnings, as classifyRemovalError does today); a project rebuilt from labels when there is no compose file.
  • Remove the dependency-order walk from pkg/compose once nothing uses it, and forbid it coming back with a depguard rule.
Details

Where each operation stands today

  • stop (stop.go): walks services in reverse dependency order and stops their containers; only the requested services, no dependents; runs the provider stop action.
  • restart (restart.go): walks in dependency order, waits for dependencies (waitDependencies), then for each container runs pre_stop, ContainerRestart and post_start; keeps only restart: true edges and includes dependents.
  • down (down.go): reverse dependency order for containers, then orphans, pre_start hook containers, networks, jobs, images and volumes, each with its own tolerance rules.

What the plan already has: a DAG of operations with phases, a bounded executor, group events, and the status published by #14544. It has operations for stop, start, remove (container, network, volume), rename, network connect/disconnect, pre_start/post_start hooks and waits.

What it lacks: a target state other than "running"; a pre_stop operation; an atomic restart; image removal; provider stop; per-scope rules for which services and which depends_on edges are followed; the removal tolerance of down.

A down as a plan

#1 run_pre_stop    web-1
#2 stop_container  web-1        depends on #1
#3 stop_container  api-1        depends on #2   (reverse dependency order)
#4 remove_container web-1, api-1
#5 remove_network  default      depends on #4   (warning if still in use)
#6 remove_volume   data         (only with -v)

Open questions

  • Restart as one operation or as stop + start.
  • down without a compose file rebuilds the project from labels, which carry neither the pre_stop hooks nor the stop grace period (docker compose -p name down does not run the hooks today). The plan can only do what the labels allow, so something has to persist what a teardown needs.
  • --dry-run has to support each new operation.

Verification

Each PR keeps make test and the e2e suites green. The golden tests of the plan do not change for the scopes that exist; new scopes get their own. Progress output is checked against the e2e checks.go vocabulary, as for the start phase.

Related: #14081 (start phase, closed), #14545 (pre_stop on a container without a process), #14544 (status-driven progress display).

Activity

  1. ndeloof commented on Nov 25, 2026

    @ndeloof
    ContributorAuthor

    waiting for #14477 to be merged

  2. added theissue type on Nov 25, 2026
  3. self-assigned this
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions