Skip to content

Never stop or remove another project's container on a name collision - #181

Merged
Mcrich23 merged 2 commits into
Mcrich23:mainfrom
adrum:feat/label-scoped-cleanup
Nov 25, 2026
Merged

Mcrich23 merged 2 commits into
Mcrich23:mainfrom
adrum:feat/label-scoped-cleanup

Conversation

@adrum

@adrum adrum commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Container names can collide across projects. Project demo with a service web-x expects its container at demo-web-x — but that's also the name project demo-web gives its service x. When that happens today, up's pre-start cleanup finds the other project's container by name and silently stops and deletes it. down stops it.

This applies the same rule #172 established for lookups to the two write paths: labels are authoritative. A container whose com.docker.compose.project label names a different project is left alone with a warning. If the current run then genuinely needs that name, creation fails with a name conflict — same as docker compose, which never removes another project's container. Unlabeled containers from before the labels existed keep the name-based behavior, since a name match is the only identity they have.

Reproduced live: with demo-web's container running, up for project demo used to delete it. Now it warns (not touching container 'demo-web-x' — its labels identify it as project 'demo-web') and the container survives. The ownership rule itself merged with #172 and is already covered there; this PR is just the two guards that use it.

@Mcrich23 Mcrich23 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

lgtm! Just please cleanup/deslop the comments.

…me collision

up's pre-start cleanup and down's stop loop find containers by
candidate names, and candidate names can collide across projects:
project demo + service web-x produce demo-web-x, which is also the
name project demo-web gives its service x. up would silently stop and
delete the other project's container before creating its own.

Labels are now authoritative: a container whose
com.docker.compose.project label names a different project is left
alone with a warning (creation then fails with a name conflict,
matching docker's behavior, instead of destroying foreign state).
Unlabeled pre-Mcrich23#126 containers keep the name-based behavior — a name
match is the only identity they have.

Same rule ps applies to its listing fallback; shared as
ComposeProject.ownsContainer with unit coverage for the foreign,
matching, and unlabeled cases.
@adrum
adrum force-pushed the feat/label-scoped-cleanup branch from 109dfb4 to b4a62c6 Compare November 25, 2026 14:35
@adrum

adrum commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@Mcrich23 we should be good now!

@adrum
adrum requested a review from Mcrich23 November 25, 2026 14:49
@Mcrich23
Mcrich23 merged commit 68e9849 into Mcrich23:main Nov 25, 2026
1 check 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.

2 participants