feat: add confirmation label when volume spec changes by qianlongzt · Pull Request #13808 · docker/compose · GitHub
Skip to content

feat: add confirmation label when volume spec changes#13808

Open
qianlongzt wants to merge 1 commit into
docker:mainfrom
qianlongzt:feat-volume-recreate-label
Open

feat: add confirmation label when volume spec changes#13808
qianlongzt wants to merge 1 commit into
docker:mainfrom
qianlongzt:feat-volume-recreate-label

Conversation

@qianlongzt

@qianlongzt qianlongzt commented May 22, 2026

Copy link
Copy Markdown

What I did

Add support for label: com.docker.compose.volume.recreate-when-spec-updated

volumes:
  my_data:
    labels:
      com.docker.compose.volume.recreate-when-spec-updated: "true"

This allows automatic handling of volume recreation when specs change, improving compatibility with CD workflows by avoiding interactive prompts.

Related issue

closes: #13807

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

@qianlongzt qianlongzt requested a review from a team as a code owner May 22, 2026 15:35
@qianlongzt qianlongzt requested review from glours and ndeloof May 22, 2026 15:35
@qianlongzt qianlongzt marked this pull request as draft May 22, 2026 15:36
@qianlongzt qianlongzt force-pushed the feat-volume-recreate-label branch 2 times, most recently from 76c9cda to 395e345 Compare May 22, 2026 15:39
@qianlongzt qianlongzt marked this pull request as ready for review May 22, 2026 15:41
@Quantum0uasar

Copy link
Copy Markdown

@qianlongzt

Copy link
Copy Markdown
Author

I checked the code and couldn't find any other resource types that currently support this kind of recreation behavior. Because of that, I'd prefer to keep the scope limited to volumes for now.

I'm also not a big fan of a value-based label such as com.docker.compose.recreate=on-spec-change.

At the moment, the behavior is essentially a yes/no decision, similar to how the --yes flag works. A boolean-style label seems simpler and easier to understand. If we introduce additional recreation policies in the future, we can revisit the label format then.

@qianlongzt qianlongzt force-pushed the feat-volume-recreate-label branch 2 times, most recently from 74d0fb6 to 0f9e44a Compare June 5, 2026 15:58
@qianlongzt

Copy link
Copy Markdown
Author

@Quantum0uasar I updated the code comments and added warning logs to show what will happen when the volume spec changes. But I couldn't find where to add the documentation. Should I add it to docs/reference/compose_up.md?

@qianlongzt qianlongzt force-pushed the feat-volume-recreate-label branch 2 times, most recently from ec6d7dc to 76e9a92 Compare June 6, 2026 15:23
@vaguul

vaguul commented Jun 6, 2026

Copy link
Copy Markdown

Thanks for adding the PR and tests. One edge case I would check before this moves forward: the current patch calls confirmVolumeRecreate(inspected.Volume.Labels, ...), so the decision is based on the labels already stored on the existing Docker volume, not the labels from the Compose file being applied.

That means these two cases can behave unexpectedly:

  • old file has no recreate label, new file adds it: Compose still prompts because the existing volume does not have the label yet
  • old file has the label, new file removes it or sets it false: Compose may still auto-recreate because the existing volume still has the old label

A useful regression test would be old.yml without com.docker.compose.volume.recreate-when-spec-updated, then new.yml with that label set to true. If the intended policy is controlled by the desired Compose spec, the recreate decision probably needs to use the desired volume.Labels rather than inspected.Volume.Labels.

Small secondary point: if the label is present with an invalid or false-ish value, it currently skips the prompt and returns false. If the label is only meant to opt in to auto-confirm, false/invalid values may be safer as normal prompt behavior instead of silently changing the decision.

close: docker#13807
Signed-off-by: qianlongzt <18493471+qianlongzt@users.noreply.github.com>
@qianlongzt qianlongzt force-pushed the feat-volume-recreate-label branch from 76e9a92 to 97612be Compare June 7, 2026 16:37
@qianlongzt

Copy link
Copy Markdown
Author

@vaguul I updated it to use a Docker Compose volume label and prompt the user for confirmation when the label is set to false.

@vaguul

vaguul commented Jun 7, 2026

Copy link
Copy Markdown

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.

Add optional auto-confirm label on volumes

3 participants