Skip to content

compat: map internal states to Docker equivalents in LibpodToContainer#28390

Merged
Honny1 merged 1 commit intocontainers:mainfrom
crawfordxx:fix-docker-compat-stopped-state-28359
Mar 31, 2026
Merged

compat: map internal states to Docker equivalents in LibpodToContainer#28390
Honny1 merged 1 commit intocontainers:mainfrom
crawfordxx:fix-docker-compat-stopped-state-28359

Conversation

@crawfordxx
Copy link
Copy Markdown
Contributor

Description

The Docker compat /containers/json endpoint was leaking podman-internal container states (stopped, stopping) that are not part of the Docker API state vocabulary. Docker clients that strictly validate the State field against the documented set (created, running, paused, restarting, exited, removing, dead) would fail with deserialization errors like:

unknown variant `stopped`, expected one of ``, `created`, `running`, `paused`,
`restarting`, `exited`, `removing`, `dead`

LibpodToContainerJSON (used by GET /containers/{name}/json) already performs the correct mapping:

  • stoppedexited
  • stoppingrunning

This PR applies the same remapping in LibpodToContainer (used by GET /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

Copy link
Copy Markdown
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

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()
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would use switch.

@TomSweeneyRedHat
Copy link
Copy Markdown
Member

LGTM
I won't merge in case you want to convert to the switch, which I would prefer too.

Copy link
Copy Markdown
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

LGTM! Once you fix the DCO and squash commits, we can merge.

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>
@crawfordxx crawfordxx force-pushed the fix-docker-compat-stopped-state-28359 branch from 6bca495 to fdf663b Compare March 29, 2026 04:04
@crawfordxx
Copy link
Copy Markdown
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 Honny1 merged commit 66c4c9c into containers:main Mar 31, 2026
82 of 83 checks passed
@Theaxiom
Copy link
Copy Markdown

Thank you! I just found this bug a few hours ago and it was crashing bollard!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/api-change Change to remote API; merits scrutiny

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Listing containers with docker compat API can leaks stopped state

4 participants