{"record":{"id":"8d3e02dc0f23b07c","repo":"testcontainers/testcontainers-java","slug":"elasticsearch-and-kibana-have-different-networks-configured","errorCode":null,"errorMessage":"Elasticsearch and Kibana have different networks configured. In managed mode both containers must share the same explicit network instance, or neither must define a network.","messagePattern":"Elasticsearch and Kibana have different networks configured\\. In managed mode both containers must share the same explicit network instance, or neither must define a network\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java","lineNumber":395,"sourceCode":"                e\n            );\n        }\n    }\n\n    private void ensureCorrectNetworkSetupForManagedMode() {\n        Network esNetwork = elasticsearch.getNetwork();\n        Network kbNetwork = this.getNetwork();\n\n        if ((esNetwork == null) != (kbNetwork == null)) {\n            throw new IllegalStateException(\n                \"Managed mode requires either both containers share the same explicit network, \" +\n                \"or neither specifies a network (KibanaContainer will create one). \"\n            );\n        }\n\n        // Both explicit: must be same\n        if (esNetwork != kbNetwork) {\n            throw new IllegalStateException(\n                \"Elasticsearch and Kibana have different networks configured. \" +\n                \"In managed mode both containers must share the same explicit network instance, \" +\n                \"or neither must define a network.\"\n            );\n        }\n    }\n\n    private void createAdHocNetwork() {\n        // Fully managed: create ad-hoc network and own it.\n        createdSharedNetwork = Network.newNetwork();\n        withNetwork(createdSharedNetwork);\n\n        // Managed-mode safety rule: by the time Kibana is configuring itself, Elasticsearch must already be\n        // started (via dependsOn)\n        String esId = requireElasticsearchContainerId();\n\n        // Elasticsearch is already created/started. Attach it to the ad-hoc network.\n        // We don't need to provide an explicit alias - we'll use the container name for DNS resolution.","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java#L377-L413","documentation":"Thrown by ensureCorrectNetworkSetupForManagedMode when both containers have explicit networks but they are different Network instances (esNetwork != kbNetwork, compared by identity). Kibana could not reach Elasticsearch across unrelated Docker networks in managed mode.","triggerScenarios":"Creating two separate Network.newNetwork() objects and assigning one to the ElasticsearchContainer and the other to KibanaContainer; or reusing the network name string but different Network instances.","commonSituations":"Two test setup helpers each creating their own network; constructing networks in different scopes/fixtures so the instances differ even if names collide.","solutions":["Share one Network instance: pass the identical Network object to both elasticsearch.withNetwork() and kibana.withNetwork().","Or drop explicit networks from both containers so KibanaContainer creates and joins them to a single network.","Extract the Network creation into one place shared by both container setups."],"exampleFix":"// before\nelasticsearch.withNetwork(Network.newNetwork());\nkibana.withNetwork(Network.newNetwork()); // different instance\n// after\nNetwork shared = Network.newNetwork();\nelasticsearch.withNetwork(shared);\nkibana.withNetwork(shared);","handlingStrategy":"validation","validationCode":"Network shared = Network.newNetwork();\nassert elasticsearch.getNetwork() == kibana.getNetwork() : \"ES and Kibana must share the same Network instance\";","typeGuard":"boolean sameNetwork(GenericContainer<?> es, GenericContainer<?> kb) { return es.getNetwork() != null && es.getNetwork() == kb.getNetwork(); }","tryCatchPattern":"try { kibana.start(); } catch (IllegalStateException e) { if (e.getMessage().contains(\"different networks configured\")) throw new ConfigException(\"Reuse one Network instance for both containers\"); throw e; }","preventionTips":["Use identity == to double-check the same Network object is passed to both containers","Hoist Network creation to a shared fixture/singleton instead of per-helper creation","Prefer the managed default (no explicit network) unless you need custom networking"],"tags":["network","elasticsearch","testcontainers","configuration"],"backgroundTag":"conflicting-config-options","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"}