-
Notifications
You must be signed in to change notification settings - Fork 5.7k
emit container status events after network reconnection (fixes #13524) #13529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
emit container status events after network reconnection (fixes #13524) #13529
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes issue #13524 where Docker Compose's TTY UI doesn't reflect the actual state of containers after they are automatically restarted by the Docker engine during a network reconfiguration. When a network's configuration diverges (e.g., IPAM/subnet changes), Compose stops and disconnects containers, recreates the network, and reconnects the containers. If the engine has a restart policy that automatically restarts those containers, the UI previously showed them as "Stopped" even though they were actually "Running".
Changes:
- Adds logic to inspect and emit container status events after reconnecting containers to a recreated network
- Adds a unit test to verify that a "Running" event is emitted for containers restarted by the engine during network recreation
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/compose/create.go | Added code to inspect containers after network reconnection and emit appropriate status events (Running, Created, or Stopped) based on their actual state |
| pkg/compose/create_test.go | Added unit test TestResolveOrCreateNetworkEmitsRunningEvent to verify the new behavior and a test event processor helper |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
pkg/compose/create.go
Outdated
| if inspected.State != nil && inspected.State.Running { | ||
| s.events.On(runningEvent(name)) | ||
| } else if inspected.State != nil && inspected.State.Status == container.StateCreated { | ||
| s.events.On(createdEvent(name)) | ||
| } else if inspected.State != nil && inspected.State.Status == container.StateExited { | ||
| s.events.On(stoppedEvent(name)) | ||
| } |
Copilot
AI
Jan 19, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional logic is inconsistent: it checks inspected.State.Running (a boolean field) for running containers but checks inspected.State.Status (a string field) for created and exited containers. For consistency and correctness, all conditions should check the Status field. The first condition should be inspected.State.Status == container.StateRunning to match the pattern used in similar code elsewhere in the codebase (e.g., ps.go lines 72-77).
pkg/compose/create.go
Outdated
| // ignore inspect errors | ||
| continue | ||
| } | ||
| name := "Container " + strings.TrimPrefix(inspected.Name, "/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use getCanonicalContainerName for consistency with other places we produce events
| } | ||
| } | ||
|
|
||
| func TestResolveOrCreateNetworkEmitsRunningEvent(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer use of e2e tests as mocks are a pain to maintain with many API calls, also in most case we don't get the actual engine behavior demonstrated by such tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi — thanks for the review and the suggestions!
I implemented both fixes you pointed out:
- Switched to using the canonical container name (now using
getContainerProgressName(tmp)) so emitted event names match other code paths. - Fixed the state check to consistently use the
Statusfield (inspected.State.Status == container.StateRunning), consistent with other code.
Per your preference for e2e tests, I added an e2e test:
TestNetworkIPAMChangeReportsStartedchanges the subnet and runsdocker compose up --progress=plain, then asserts the output contains the expected container state transition (Stopped then Started or Recreated).
I left the focused unit test as an additional guard; if you prefer to rely only on e2e tests I can remove the unit test in a follow-up. Happy to tweak wording or add more coverage if you prefer.
— Mahesh
8f43d7c to
24d36c1
Compare
…#13524) Signed-off-by: Mahesh Thakur <maheshthakur9152@gmail.com>
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com> Signed-off-by: Mahesh Thakur <maheshthakur9152@gmail.com>
Signed-off-by: Mahesh Thakur <maheshthakur9152@gmail.com>
Signed-off-by: Mahesh Thakur <maheshthakur9152@gmail.com>
24d36c1 to
fb09730
Compare
Summary
Root cause
Stopped.What I changed
RunningeventCreatedeventStoppedeventTestResolveOrCreateNetworkEmitsRunningEventto assert that a running event is emitted for a container restarted by the engine.Files changed
Testing done
Notes for reviewers
Fixes: #13524