{"record":{"id":"a235236457fa82dd","repo":"testcontainers/testcontainers-java","slug":"reuse-was-requested-but-the-environment-does-not-support-the","errorCode":null,"errorMessage":"Reuse was requested but the environment does not support the reuse of containers\nTo enable reuse of containers, you must set 'testcontainers.reuse.enable=true' in a file located at {}","messagePattern":"Reuse was requested but the environment does not support the reuse of containers\nTo enable reuse of containers, you must set 'testcontainers\\.reuse\\.enable=true' in a file located at (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/src/main/java/org/testcontainers/containers/GenericContainer.java","lineNumber":407,"sourceCode":"                        .getLabels()\n                        .put(COPIED_FILES_HASH_LABEL, Long.toHexString(hashCopiedFiles().getValue()));\n\n                    String hash = hash(createCommand);\n\n                    containerId = findContainerForReuse(hash).orElse(null);\n\n                    if (containerId != null) {\n                        logger().info(\"Reusing container with ID: {} and hash: {}\", containerId, hash);\n                        reused = true;\n                    } else {\n                        logger().debug(\"Can't find a reusable running container with hash: {}\", hash);\n\n                        createCommand.getLabels().put(HASH_LABEL, hash);\n                    }\n                    reusable = true;\n                } else {\n                    logger()\n                        .warn(\n                            \"\" +\n                            \"Reuse was requested but the environment does not support the reuse of containers\\n\" +\n                            \"To enable reuse of containers, you must set 'testcontainers.reuse.enable=true' in a file located at {}\",\n                            Paths.get(System.getProperty(\"user.home\"), \".testcontainers.properties\")\n                        );\n                    reusable = false;\n                }\n            } else {\n                reusable = false;\n            }\n\n            if (!reusable) {\n                //noinspection deprecation\n                createCommand = ResourceReaper.instance().register(this, createCommand);\n            }\n\n            if (!reused) {\n                containerId = createCommand.exec().getId();","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/core/src/main/java/org/testcontainers/containers/GenericContainer.java#L389-L425","documentation":"GenericContainer.tryStart() logs this warning when withReuse(true) is set but Testcontainers reuse is not enabled globally. Reuse requires opt-in via testcontainers.reuse.enable=true in ~/.testcontainers.properties; without it the container silently starts without reuse (reusable=false) rather than failing.","triggerScenarios":"Calling .withReuse(true) on a container while ~/.testcontainers.properties lacks testcontainers.reuse.enable=true (or the property file is missing).","commonSituations":"Developers enabling reuse locally for faster dev loops then running on CI or a teammate machine where the flag was never set; fresh environments after cloning.","solutions":["Add testcontainers.reuse.enable=true to ~/.testcontainers.properties","Or drop withReuse(true) if reuse is not needed","Provide the properties file in CI (e.g. via setup step) when relying on reuse for speed"],"exampleFix":"// before (reused silently disabled)\nGenericContainer<?> c = new GenericContainer<>(\"redis:7\").withReuse(true);\n// after: add to ~/.testcontainers.properties\ntestcontainers.reuse.enable=true","handlingStrategy":"validation","validationCode":"// Fail fast in CI if reuse was requested but not enabled\nProperties props = new Properties();\nprops.load(new FileInputStream(\n    Paths.get(System.getProperty(\"user.home\"), \".testcontainers.properties\").toFile()));\nboolean reuseEnabled = \"true\".equals(props.getProperty(\"testcontainers.reuse.enable\"));\nif (!reuseEnabled) {\n    throw new IllegalStateException(\"Enable reuse: testcontainers.reuse.enable=true in ~/.testcontainers.properties\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Commit a setup step that writes testcontainers.reuse.enable=true to ~/.testcontainers.properties in CI","Only call withReuse(true) in environments where the flag is verified","Remember reuse is off by default by design"],"tags":["container-reuse","configuration","testcontainers-properties","non-fatal"],"backgroundTag":"feature-not-enabled","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"}