{"record":{"id":"3f8defb565348f42","repo":"testcontainers/testcontainers-java","slug":"withreuse-true-is-not-supported-for-kibanacontainer-in","errorCode":null,"errorMessage":"withReuse(true) is not supported for KibanaContainer in managed mode. Use external mode (withElasticsearchUrl) to enable reuse.","messagePattern":"withReuse\\(true\\) is not supported for KibanaContainer in managed mode\\. Use external mode \\(withElasticsearchUrl\\) to enable reuse\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java","lineNumber":156,"sourceCode":"     * <p><b>Supported in external mode only.</b> When Kibana is configured via\n     * {@link #withElasticsearchUrl(String)}, the container configuration is fully deterministic\n     * and TC can reliably locate the running container on subsequent runs.\n     *\n     * <p>Reuse is <b>not supported in managed mode</b> (i.e. when this container was created with\n     * an {@link ElasticsearchContainer}). Managed mode introduces several non-deterministic inputs\n     * into the container hash on every run (ad-hoc network ID, random network alias, fresh service\n     * account token), so TC always sees a different hash and starts a fresh container instead of\n     * reusing the existing one. This is a framework-level characteristic that affects any container\n     * connected via {@code withNetwork()} — not specific to {@code KibanaContainer}.\n     *\n     * @param reusable whether to enable container reuse\n     * @return this container instance\n     * @throws IllegalStateException if {@code reusable} is {@code true} and managed mode is active\n     */\n    @Override\n    public KibanaContainer withReuse(boolean reusable) {\n        if (reusable && elasticsearch != null) {\n            throw new IllegalStateException(\n                \"withReuse(true) is not supported for KibanaContainer in managed mode. \" +\n                \"Use external mode (withElasticsearchUrl) to enable reuse.\"\n            );\n        }\n        return super.withReuse(reusable);\n    }\n\n    /**\n     * Configures the Elasticsearch URL for external mode.\n     *\n     * @param elasticsearchUrl the Elasticsearch URL (e.g., \"https://my.fancy.setup.elastic.cloud:9200\")\n     * @return this container instance\n     * @throws IllegalStateException if already using managed mode\n     */\n    public KibanaContainer withElasticsearchUrl(String elasticsearchUrl) {\n        if (elasticsearch != null) {\n            throw new IllegalStateException(\"Cannot set Elasticsearch URL when using Elasticsearch container\");\n        }","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java#L138-L174","documentation":"KibanaContainer overrides withReuse(boolean) and refuses reuse when the container is in managed mode (an Elasticsearch container was supplied via withElasticsearch(...)), because a reusable Kibana instance depends on a managed ES container whose lifecycle cannot be shared across test runs. Reuse is only supported in external mode where Kibana points at a fixed Elasticsearch URL.","triggerScenarios":"Calling kibana.withReuse(true) after (or before) using withElasticsearch(elasticsearchContainer) — i.e. any reuse attempt in managed mode.","commonSituations":"Developers enabling Testcontainers reuse to speed up slow Kibana startups while also letting the library spin up its own Elasticsearch container.","solutions":["Switch to external mode: call withElasticsearchUrl(\"http://host:9200\") pointing at an already-running/reusable Elasticsearch instead of withElasticsearch(...).","Then call withReuse(true) — it will pass through to the parent container implementation.","Enable Testcontainers reuse support (.testcontainers.properties: testcontainers.reuse.enable=true) and ensure credentials/config are stable across runs.","Alternatively keep managed mode and drop withReuse(true)."],"exampleFix":"// before\nnew KibanaContainer(IMAGE)\n    .withElasticsearch(esContainer)\n    .withReuse(true); // throws\n// after\nnew KibanaContainer(IMAGE)\n    .withElasticsearchUrl(\"http://localhost:9200\")\n    .withReuse(true);","handlingStrategy":"validation","validationCode":"boolean managedMode = esContainer != null; boolean reuseDesired = true; if (managedMode && reuseDesired) { /* switch to withElasticsearchUrl instead */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember: reuse requires external mode (withElasticsearchUrl) for KibanaContainer.","Enable testcontainers.reuse.enable=true in ~/.testcontainers.properties when using reuse.","Keep managed-mode builders free of withReuse(true).","Centralize Kibana container construction in a helper that enforces one mode."],"tags":["kibana","elasticsearch","testcontainers","reuse","unsupported"],"backgroundTag":"unsupported-operation","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"}