testcontainers/testcontainers-java · error · IllegalStateException
Path already configured for copy
Error message
Path already configured for copy: ${mountableFile} What it means
Guard in GenericContainer.withCopyFileToContainer: the same MountableFile source was already registered in copyToFileContainerPathMap, i.e. a duplicate copy of the same path was configured. Testcontainers forbids configuring the same source for copy twice, so an IllegalStateException is thrown naming the offending file.
Solutions
- Call withCopyFileToContainer only once per unique MountableFile source
- Remove duplicate copy registrations of the same path from container setup
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at core/src/main/java/org/testcontainers/containers/GenericContainer.java:1265 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12).
Data as JSON: /api/errors/1cd2e2b4e6d08c77.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/testcontainers/containers/GenericContainer.java:1265
return self();
}
/**
* {@inheritDoc}
*/
@Override
public SELF withWorkingDirectory(String workDir) {
this.setWorkingDirectory(workDir);
return self();
}
/**
* {@inheritDoc}
*/
@Override
public SELF withCopyFileToContainer(MountableFile mountableFile, String containerPath) {
if (copyToFileContainerPathMap.containsKey(mountableFile)) {
throw new IllegalStateException("Path already configured for copy: " + mountableFile);
}
copyToFileContainerPathMap.put(mountableFile, containerPath);
return self();
}
/**
* {@inheritDoc}
*/
@Override
public SELF withCopyToContainer(Transferable transferable, String containerPath) {
copyToTransferableContainerPathMap.put(transferable, containerPath);
return self();
}
/**
* Get the IP address that this container may be reached on (may not be the local machine).
*
* @return an IP addressView on GitHub (pinned to 8e549514e3)