Skip to content
Latchkey

Testcontainers "Timed out waiting for container ... to be ready" in CI

Testcontainers polled the readiness condition (a listening port, a log line, or an HTTP endpoint) and never saw it satisfied before the timeout expired. On CI this is usually slowness or a wrong readiness signal, not a broken container.

What this error means

Setup fails with "Timed out waiting for container ... to be ready!" after the default wait period. The same test passes locally where the container starts faster.

Testcontainers
org.testcontainers.containers.ContainerLaunchException: Timed out waiting for container port to open
(localhost ports: [49277] should be listening)

Common causes

CI is slower than local, so the default timeout is too tight

Cold image pulls and shared CI CPUs stretch startup past the default readiness timeout that passes comfortably on a developer machine.

The wait strategy watches the wrong signal

Waiting for a port that opens before the app is truly ready, or a log line that changed, causes the strategy to poll something that never resolves in time.

How to fix it

Extend the startup timeout for CI

Raise the wait-strategy timeout so a slow but healthy boot is accepted.

Java
.waitingFor(Wait.forHttp("/health").forStatusCode(200)
    .withStartupTimeout(Duration.ofMinutes(2)))

Wait on a true readiness signal

Prefer a health endpoint or a stable "ready" log message over a bare open port, so readiness reflects the app, not just the socket.

Java
.waitingFor(Wait.forLogMessage(".*database system is ready to accept connections.*", 1))

How to prevent it

  • Tune wait-strategy timeouts for CI, not just local speed.
  • Wait on an application-level readiness signal, not just an open port.
  • Pre-pull heavy images so the wait clock does not include the pull.

Frequently asked questions

What causes ""Timed out waiting for container ... to be ready""?
Cold image pulls and shared CI CPUs stretch startup past the default readiness timeout that passes comfortably on a developer machine.
How do I fix "Timed out waiting for container ... to be ready"?
Raise the wait-strategy timeout so a slow but healthy boot is accepted.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card