Skip to content

Conversation

@VolkovIO
Copy link

@VolkovIO VolkovIO commented Jan 29, 2026

Summary

GenericContainer.getLogs() can return empty output when container startup fails or the container exits very quickly (e.g. one-shot commands). This PR adds an opt-in mechanism to capture container logs in memory so they can still be retrieved after a failed start.

Changes

  • Add withLogCapture() to enable in-memory log capture (disabled by default).
  • Add getCapturedLogs() to retrieve captured stdout/stderr.
  • Add tests covering default behavior (no capture) and enabled capture on startup failure.

Rationale

The implementation reuses the existing log consumer mechanism by registering a ToStringConsumer when log capture is enabled, without changing default behavior or getLogs() semantics.

Testing

  • GenericContainerLogCaptureTest verifies:
    • no captured logs by default when startup fails
    • captured logs contain container output when withLogCapture() is enabled

Fixes #11215

This allows retrieving container output even when startup fails or the container exits quickly, where getLogs() may return empty output.

Fixes testcontainers#11215"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: GenericContainer.getLogs() returns empty when container fails to start

2 participants