Skip to content

API: implement /containers/{id}/wait (blocking exit-code endpoint) #3

Description

@adrianlungu

Long-poll endpoint that blocks until the container exits and returns the exit code as JSON.

Surfaced by

  • `docker run -d` reports `error waiting for container: Error response from daemon: 404 page not found` even when the container starts successfully — the CLI always calls /wait after start
  • `docker wait ` fails outright
  • Testcontainers and most orchestration tooling call this after creating a container

What it needs

`POST /containers/{id}/wait` with optional `condition` query param:

  • `not-running` (default) — container is not running (exited)
  • `next-exit` — wait for exit after the current run
  • `removed` — waits until the container is removed

Response shape:

```json
{
"StatusCode": 0,
"Error": null
}
```

Scope

Small compared to /attach — single long-poll, no stream framing, no stdin. Just:

  1. Subscribe to `container.die` / `container.stop` events on the existing bus
  2. Block until the matching event arrives for the given ID
  3. Emit StatusCode from the container's exit code (need to start tracking this — currently only /exec/{id}/json does)
  4. Honor ctx cancellation cleanly

Bucket this with /attach implementation since they share "track container exit code" plumbing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    roadmapPlanned work, tracked in the roadmap

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions