{"record":{"id":"69172bb520764a8a","repo":"testcontainers/testcontainers-java","slug":"wait-strategy-failed-container-is-removed","errorCode":null,"errorMessage":"Wait strategy failed. Container is removed","messagePattern":"Wait strategy failed\\. Container is removed","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/testcontainers/containers/GenericContainer.java","lineNumber":498,"sourceCode":"                // Bail out, don't wait for the port to start listening.\n                // (Exception thrown here will be caught below and wrapped)\n                throw new IllegalStateException(\"Container did not start correctly.\");\n            }\n\n            // Wait until the process within the container has become ready for use (e.g. listening on network, log message emitted, etc).\n            try {\n                waitUntilContainerStarted();\n            } catch (Exception e) {\n                logger().debug(\"Wait strategy threw an exception\", e);\n                InspectContainerResponse inspectContainerResponse = null;\n                try {\n                    inspectContainerResponse = dockerClient.inspectContainerCmd(containerId).exec();\n                } catch (NotFoundException notFoundException) {\n                    logger().debug(\"Container {} not found\", containerId, notFoundException);\n                }\n\n                if (inspectContainerResponse == null) {\n                    throw new IllegalStateException(\"Wait strategy failed. Container is removed\", e);\n                }\n\n                InspectContainerResponse.ContainerState state = inspectContainerResponse.getState();\n                if (Boolean.TRUE.equals(state.getDead())) {\n                    throw new IllegalStateException(\"Wait strategy failed. Container is dead\", e);\n                }\n\n                if (Boolean.TRUE.equals(state.getOOMKilled())) {\n                    throw new IllegalStateException(\n                        \"Wait strategy failed. Container crashed with out-of-memory (OOMKilled)\",\n                        e\n                    );\n                }\n\n                String error = state.getError();\n                if (!StringUtils.isBlank(error)) {\n                    throw new IllegalStateException(\"Wait strategy failed. Container crashed: \" + error, e);\n                }","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/GenericContainer.java#L480-L516","documentation":"When the wait strategy throws (typically a timeout), tryStart inspects the container to give a better diagnostic. If the container no longer exists — inspectContainerCmd throws NotFoundException or returns nothing — it throws this IllegalStateException: the container was removed (often by Ryuk or by exiting with auto-remove) while the wait strategy was waiting.","triggerScenarios":"Container exits and is auto-removed (--rm semantics / Testcontainers cleanup) before/while the wait strategy runs; Ryuk reaper removes the container due to session termination; a resource reaper triggered mid-start.","commonSituations":"Wait strategy timeout far longer than container lifetime so the container dies and disappears before the check; JVM running tests with a session ID whose containers get reaped; container crashed with an image that has AutoRemove behavior.","solutions":["Look at the earlier container logs in the test output — the container exited for a reason captured there.","Fix the underlying container crash (usually the 'Caused by' wait strategy timeout plus exit logs).","Shorten or correct the wait strategy so it matches the container's real startup behavior.","Check that no external cleanup (Ryuk, reaper, CI timeout) is killing containers mid-test."],"exampleFix":"// before\ncontainer.waitingFor(Wait.forHttp(\"/health\").forStatusCode(200)); // container dies before port ever opens\n// after\ncontainer.waitingFor(Wait.forListeningPort()).withStartupTimeout(Duration.ofSeconds(60));","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n    container.start();\n} catch (ContainerLaunchException e) {\n    if (e.getCause() instanceof IllegalStateException\n            && e.getCause().getMessage().contains(\"Container is removed\")) {\n        // container died and was reaped — check earlier logs for the exit reason\n    }\n    throw e;\n}","preventionTips":["Match the wait strategy to the container's actual readiness signal.","Keep Ryuk/reaper timeouts longer than your test session.","Avoid AutoRemove-style images if you need post-mortem inspection."],"tags":["docker","wait-strategy","container-removed"],"backgroundTag":"container-wait-strategy-failed","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}