{"record":{"id":"d7d54805dac78b7b","repo":"testcontainers/testcontainers-java","slug":"elasticsearch-containerid-is-not-available-in-managed-mode","errorCode":null,"errorMessage":"Elasticsearch containerId is not available. In managed mode, Elasticsearch must be started via dependsOn(elasticsearch) before KibanaContainer is started.","messagePattern":"Elasticsearch containerId is not available\\. In managed mode, Elasticsearch must be started via dependsOn\\(elasticsearch\\) before KibanaContainer is started\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java","lineNumber":494,"sourceCode":"                .client()\n                .inspectNetworkCmd()\n                .withNetworkId(network.getId())\n                .exec()\n                .getName();\n            if (networkName != null) {\n                return networks.get(networkName);\n            }\n        } catch (Exception e) {\n            // Ignore and return null\n        }\n\n        return null;\n    }\n\n    private String requireElasticsearchContainerId() {\n        String id = elasticsearch.getContainerId();\n        if (StringUtils.isBlank(id)) {\n            throw new IllegalStateException(\n                \"Elasticsearch containerId is not available. In managed mode, Elasticsearch must be started via dependsOn(elasticsearch) \" +\n                \"before KibanaContainer is started.\"\n            );\n        }\n        return id.trim();\n    }\n\n    private void connectRunningContainerToNetwork(String containerId, Network network) {\n        String networkId = network.getId();\n\n        try {\n            DockerClientFactory\n                .instance()\n                .client()\n                .connectToNetworkCmd()\n                .withContainerId(containerId)\n                .withNetworkId(networkId)\n                .exec();","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java#L476-L512","documentation":"KibanaContainer in managed mode requires an already-started Elasticsearch container. requireElasticsearchContainerId calls elasticsearch.getContainerId() and throws IllegalStateException when the id is blank, i.e. the Elasticsearch container object exists but has not been started yet. The library throws this instead of silently connecting Kibana to a nonexistent ES instance.","triggerScenarios":"Calling kibana.token() (or any path through esId/requireElasticsearchContainerId) when KibanaContainer is in managed mode (constructed with a real ElasticsearchContainer) but that ElasticsearchContainer was never started, or was created but only referenced via dependsOn without being the started instance Kibana holds.","commonSituations":"Declaring new KibanaContainer(elasticsearch) but calling token()/config access before starting the containers; forgetting that dependsOn only orders lifecycle and does not itself start ES; accessing the token in a @BeforeEach that runs before container startup; accidentally constructing Kibana with a fresh ElasticsearchContainer that is never part of the test lifecycle.","solutions":["Start the ElasticsearchContainer before using Kibana features: ensure elasticsearch.start() is invoked (directly or via @Testcontainers/@Container) and that KibanaContainer is declared with dependsOn(elasticsearch).","Verify the KibanaContainer was built with the actual started ElasticsearchContainer instance, not a second, unstarted instance.","Move any token()/ES-id access to after container startup (e.g. inside the test method or after both containers have started)."],"exampleFix":"// before\nKibanaContainer kibana = new KibanaContainer(DockerImageName.parse(...));\nString token = kibana.token(); // ES not started\n\n// after\n@Container\nElasticsearchContainer es = new ElasticsearchContainer(...);\n@Container\nKibanaContainer kibana = new KibanaContainer(es).dependsOn(es);\n// access kibana.token() only in the test body, after containers started","handlingStrategy":"validation","validationCode":"// before using kibana features in managed mode\nassert es.isRunning() : \"Elasticsearch container must be started before Kibana usage\";\nString esId = es.getContainerId();\nif (esId == null || esId.isBlank()) throw new IllegalStateException(\"Start ElasticsearchContainer first\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use @Testcontainers/@Container annotations so startup order and lifecycle are managed for you.","Always pair KibanaContainer with dependsOn(elasticsearch) in managed mode.","Only call token()/config accessors after both containers report isRunning()."],"tags":["testcontainers","elasticsearch","kibana","lifecycle","managed-mode"],"backgroundTag":"invalid-state-transition","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"}