compat: map internal states to Docker equivalents in LibpodToContainer#28390
Merged
Honny1 merged 1 commit intocontainers:mainfrom Mar 31, 2026
Merged
Conversation
Honny1
approved these changes
Mar 27, 2026
Member
Honny1
left a comment
There was a problem hiding this comment.
LGTM, I have just style code comment.
Comment on lines
+313
to
+323
| if state == define.ContainerStateCreated { | ||
| stateStr = define.ContainerStateConfigured.String() | ||
| } | ||
| // "stopped" and "stopping" are podman-internal states with no Docker equivalent. | ||
| // Map them to the nearest Docker state so the compat API never leaks internal states. | ||
| if state == define.ContainerStateStopped { | ||
| stateStr = define.ContainerStateExited.String() | ||
| } | ||
| if state == define.ContainerStateStopping { | ||
| stateStr = define.ContainerStateRunning.String() | ||
| } |
Member
|
LGTM |
Honny1
reviewed
Mar 28, 2026
The Docker compat /containers/json endpoint was leaking podman-internal
container states ("stopped", "stopping") that are not valid Docker API
states. Docker clients that strictly validate the State field against
the documented set ("created", "running", "paused", "restarting",
"exited", "removing", "dead") would fail with deserialization errors.
LibpodToContainerJSON already performs this mapping correctly:
- "stopped" → "exited"
- "stopping" → "running"
Apply the same remapping in LibpodToContainer using a switch statement
so the list endpoint behaves consistently with the inspect endpoint.
Add a test assertion to the compat /containers/json test to verify
that a stopped container is reported with State="exited".
Fixes containers#28359
Signed-off-by: crawfordxx <crawfordxx@users.noreply.github.com>
6bca495 to
fdf663b
Compare
Contributor
Author
|
Updated: squashed to a single commit and converted the if-chain to a switch statement as suggested. The switch cleanly handles all three state remappings (created→configured, stopped→exited, stopping→running) in one place. DCO sign-off is included. |
Honny1
approved these changes
Mar 31, 2026
|
Thank you! I just found this bug a few hours ago and it was crashing bollard! |
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.
Description
The Docker compat
/containers/jsonendpoint was leaking podman-internal container states (stopped,stopping) that are not part of the Docker API state vocabulary. Docker clients that strictly validate theStatefield against the documented set (created,running,paused,restarting,exited,removing,dead) would fail with deserialization errors like:LibpodToContainerJSON(used byGET /containers/{name}/json) already performs the correct mapping:stopped→exitedstopping→runningThis PR applies the same remapping in
LibpodToContainer(used byGET /containers/json) so both endpoints behave consistently.A test assertion is added to the compat list endpoint test to verify that a stopped container is reported with
State="exited".Fixes #28359