Repository navigation
Description
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.goalone 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_stophooks as a plan operation, before every plan stop. Fixes the table above (uprecreate, scale down) and is useful on its own. - Lock the current behavior of
stop,restartanddownwith e2e scenarios before touching them:-p name downwithout the compose file,--remove-orphans,-v,--rmi, services disabled by a profile, already stopped containers,restartwith dependents andrestart: trueedges, partial failure. -
stopon the plan. A target state per resource (running, stopped, removed) in the reconciler; a scope for it; the providerstopaction; services selected without their dependents. -
restarton the plan. A restart operation (atomicContainerRestartor stop + start, to decide); dependency order with the existing wait nodes; onlyrestart: trueedges; hooks around it. -
downon the plan. Containers in reverse dependency order, orphans,pre_starthook containers, networks, volumes, images, jobs; tolerant removals ("already gone", "still in use" as warnings, asclassifyRemovalErrordoes today); a project rebuilt from labels when there is no compose file. - Remove the dependency-order walk from
pkg/composeonce nothing uses it, and forbid it coming back with adepguardrule.
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 providerstopaction.restart(restart.go): walks in dependency order, waits for dependencies (waitDependencies), then for each container runspre_stop,ContainerRestartandpost_start; keeps onlyrestart: trueedges and includes dependents.down(down.go): reverse dependency order for containers, then orphans,pre_starthook 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.
downwithout a compose file rebuilds the project from labels, which carry neither thepre_stophooks nor the stop grace period (docker compose -p name downdoes not run the hooks today). The plan can only do what the labels allow, so something has to persist what a teardown needs.--dry-runhas 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
ndeloof commentedon Nov 25, 2026
waiting for #14477 to be merged