testcontainers/testcontainers-java · warning
Reuse was requested but the environment does not support…
Error message
Reuse was requested but the environment does not support the reuse of containers
To enable reuse of containers, you must set 'testcontainers.reuse.enable=true' in a file located at {} What it means
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.
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
Example fix
// before (reused silently disabled)
GenericContainer<?> c = new GenericContainer<>("redis:7").withReuse(true);
// after: add to ~/.testcontainers.properties
testcontainers.reuse.enable=true Defensive patterns
Strategy: validation
Validate before calling
// Fail fast in CI if reuse was requested but not enabled
Properties props = new Properties();
props.load(new FileInputStream(
Paths.get(System.getProperty("user.home"), ".testcontainers.properties").toFile()));
boolean reuseEnabled = "true".equals(props.getProperty("testcontainers.reuse.enable"));
if (!reuseEnabled) {
throw new IllegalStateException("Enable reuse: testcontainers.reuse.enable=true in ~/.testcontainers.properties");
} Prevention
- 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
When it happens
Trigger: Calling .withReuse(true) on a container while ~/.testcontainers.properties lacks testcontainers.reuse.enable=true (or the property file is missing).
Common situations: 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.
Related errors
- Services named do not exist, but wait conditions have been…
- Could not get a port for
- This container does not support reuse
- Changing startup timeout is not supported with mode
- Unexpected scheme
AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12).
Data as JSON: /api/errors/a235236457fa82dd.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/testcontainers/containers/GenericContainer.java:407
.getLabels()
.put(COPIED_FILES_HASH_LABEL, Long.toHexString(hashCopiedFiles().getValue()));
String hash = hash(createCommand);
containerId = findContainerForReuse(hash).orElse(null);
if (containerId != null) {
logger().info("Reusing container with ID: {} and hash: {}", containerId, hash);
reused = true;
} else {
logger().debug("Can't find a reusable running container with hash: {}", hash);
createCommand.getLabels().put(HASH_LABEL, hash);
}
reusable = true;
} else {
logger()
.warn(
"" +
"Reuse was requested but the environment does not support the reuse of containers\n" +
"To enable reuse of containers, you must set 'testcontainers.reuse.enable=true' in a file located at {}",
Paths.get(System.getProperty("user.home"), ".testcontainers.properties")
);
reusable = false;
}
} else {
reusable = false;
}
if (!reusable) {
//noinspection deprecation
createCommand = ResourceReaper.instance().register(this, createCommand);
}
if (!reused) {
containerId = createCommand.exec().getId();View on GitHub (pinned to 8e549514e3)