Repository navigation
fix(up): recreate a stopped container whose network was removed - #14519
Merged
Merged
Conversation
A stopped container still refers to the networks it was attached to. When one of them was removed, up created the network again but started the old container, and the engine refused: "network <id> not found". The network check of mustRecreate only ran for running containers, so a stopped one was never compared with the network of the project. It now runs whatever the state of the container, like the check of the volumes. A network that no longer exists is not in the observed state, so a container attached to a network of that name refers to the removed one and is recreated. A container that was created but never started has no network ID yet: it is left alone, rather than taken for one attached to another network. Fixes docker#14516 Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
Lower-confidence findings (not posted inline)
- [low] pkg/compose/reconcile.go:1130 —
netID == "" && name == obs.Nameexempts any container entry with an empty network ID from mismatch detection, without gating on StateCreated (confidence: weak 52/100)
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does, in one sentence
Makes
uprecreate a stopped container whose network was removed, instead of starting it on a network that no longer exists.Context
A stopped container still refers to the networks it was attached to. When one of them is removed (
docker network rm),upcreates the network again but starts the old container, and the engine refuses:failed to set up container networking: network <id> not found. The check that a container is attached to the expected networks only ran for running containers, so a stopped one was never compared with the network of the project. A running container in the same situation is already recreated.What the PR brings
up,stop,network rm,up) and expects the service running in a new container; another one guards the created-but-never-started case. A unit test covers the reconciliation for each state.Only networks Compose manages are concerned: external ones are untouched.
Fixes #14516
🤖 Generated with Claude Code