Skip to content

fix(down): keep volumes other services use on down -v with services - #14449

Merged
glours merged 1 commit into
docker:mainfrom
htoyoda18:fix/down-volumes-of-selected-services
Nov 13, 2026
Merged

glours merged 1 commit into
docker:mainfrom
htoyoda18:fix/down-volumes-of-selected-services

Conversation

@htoyoda18

@htoyoda18 htoyoda18 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does

docker compose down -v <service> no longer removes the volumes of services it does not tear down. Before, it also tried to remove the volumes of the selected services' dependencies, and of services outside the selection that share a volume. Only the engine's "in use" check kept them, so once the dependency's container was gone (for example after a plain down), down -v web deleted the data volume of the db that web depends on.

Related issue

Fixes #14448

Changes made

  • pkg/compose/down.go:
    • down records the services it tears down: the selected ones and those that depend on them.
    • When services are given, ensureVolumesDown skips any volume that another service uses, including the services the selection disabled. It reuses volumeConsumers from reconcile.go, which also follows volumes_from.
    • A plain down -v is unchanged.
  • pkg/compose/down_test.go: adds TestEnsureVolumesDown_KeepsVolumesOfOtherServices, and updates the existing callers for the new parameter.
  • pkg/e2e/volumes_test.go and testdata/TestDownVolumesOfSelectedServices/compose.yaml: adds the scenario TestDownVolumesOfSelectedServices. After up and down, down -v web removes only web's own volume. It keeps the dependency's volume and the one web shares with an unrelated service.

Testing done

  • Unit tests pass: make test
  • E2E tests pass: make e2e-compose or make e2e-compose-standalone
  • Linting passes: make lint
  • Code formatted: make fmt
  • Manually tested (describe):

AI tool used (if applicable)

AI Tool:

Additional context

(not mandatory) A picture of a cute animal, if possible in relation to what you did

image

@htoyoda18
htoyoda18 marked this pull request as ready for review November 4, 2026 01:09
@htoyoda18
htoyoda18 requested review from a team as code owners November 4, 2026 01:09
@htoyoda18
htoyoda18 requested review from glours and ndeloof November 4, 2026 01:09
@ndeloof

ndeloof commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Thanks, this fixes the reported case and the approach looks right. Two non-blocking follow-ups:

  • Without a compose file (-p <name> down -v <service>), the project is rebuilt from the existing containers, so a service with no container is unknown and its volumes are not protected. This is a limit of the fix, not a regression.
  • scope == nil now means "no scope, remove everything". It is never empty when services are given today, but an explicit boolean would be safer than this sentinel.

ndeloof
ndeloof previously approved these changes Nov 4, 2026
@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Signed-off-by: hiroto.toyoda <hiroto.toyoda@dena.com>
@htoyoda18
htoyoda18 force-pushed the fix/down-volumes-of-selected-services branch from 3cb13eb to 15e6847 Compare November 5, 2026 23:35
@htoyoda18

Copy link
Copy Markdown
Contributor Author

@ndeloof I rebased onto main to resolve the conflict with the move of the dependency graph to internal/depgraph (d2582e9). The only change from the commit you approved is the call InReverseDependencyOrder → depgraph.InReverseDependencyOrder. The push dismissed your approval, so could you re-approve and approve the CI workflows when you have a moment? Thanks!

@glours glours left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@glours
glours merged commit 769fda7 into docker:main Nov 13, 2026
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] down -v <service> removes the named volumes of the service's dependencies

3 participants