{"record":{"id":"141235dba2464a35","repo":"testcontainers/testcontainers-java","slug":"managed-mode-requires-either-both-containers-share-the-same","errorCode":null,"errorMessage":"Managed mode requires either both containers share the same explicit network, or neither specifies a network (KibanaContainer will create one). ","messagePattern":"Managed mode requires either both containers share the same explicit network, or neither specifies a network \\(KibanaContainer will create one\\)\\. ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java","lineNumber":387,"sourceCode":"        try {\n            return elasticsearch.copyFileFromContainer(elasticsearch.getCertPath(), IOUtils::toByteArray);\n        } catch (Exception e) {\n            throw new IllegalStateException(\n                \"Failed to copy Elasticsearch HTTP CA certificate from '\" +\n                elasticsearch.getCertPath() +\n                \"'. \" +\n                \"In managed HTTPS mode, KibanaContainer requires access to the Elasticsearch HTTP CA.\",\n                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();","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java#L369-L405","documentation":"Thrown by ensureCorrectNetworkSetupForManagedMode when exactly one of the Elasticsearch container and the KibanaContainer has an explicit Docker network configured (XOR condition (esNetwork == null) != (kbNetwork == null)). In managed mode the two must be on the same network so Kibana can reach Elasticsearch by DNS name.","triggerScenarios":"Calling kibana.withNetwork(myNetwork) while the ElasticsearchContainer has no network (or vice versa) before starting KibanaContainer in managed (constructor-injected) mode.","commonSituations":"Adding a custom network only to the Kibana container for other tooling; copy-pasting a network setup example onto just one of the two containers.","solutions":["Apply the same Network instance to both containers (elasticsearch.withNetwork(network) and kibana.withNetwork(network)).","Or remove withNetwork from both and let KibanaContainer create a shared network automatically.","Ensure withCreateContainerCmdModifier-based network hacks aren't applied to only one side."],"exampleFix":"// before\nNetwork net = Network.newNetwork();\nkibana.withNetwork(net); // only Kibana has a network\n// after\nNetwork net = Network.newNetwork();\nelasticsearch.withNetwork(net);\nkibana.withNetwork(net);","handlingStrategy":"validation","validationCode":"Network net = Network.newNetwork();\nelasticsearch.withNetwork(net);\nkibana.withNetwork(net); // XOR check: both or neither","typeGuard":"boolean networksConsistent(GenericContainer<?> es, GenericContainer<?> kb) { return (es.getNetwork() == null) == (kb.getNetwork() == null); }","tryCatchPattern":"try { kibana.start(); } catch (IllegalStateException e) { if (e.getMessage().contains(\"Managed mode requires\")) throw new ConfigException(\"Apply withNetwork to both or neither container\"); throw e; }","preventionTips":["Create one Network instance and share it between both containers","Or skip withNetwork entirely and let KibanaContainer create a network","Never configure networks on only one container of a managed pair"],"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"}