| [ Web Proxy ] |
| Viewing: https://java.testcontainers.org/supported_docker_environment/../../features/files/ | [Back] [Original] |
Files can be copied into the container before startup, or can be copied from the container after the container has started.
Note
This is the recommended approach for portability cross-docker environments.
GenericContainer<?> container = new GenericContainer<>(TestImages.TINY_IMAGE)
.withCommand("sleep", "3000")
.withCopyFileToContainer(
MountableFile.forClasspathResource("/mappable-resource/"),
directoryInContainer
)
Using Transferable, file content will be placed in the specified location.
GenericContainer<?> container = new GenericContainer<>(TestImages.TINY_IMAGE)
.withStartupCheckStrategy(new NoopStartupCheckStrategy())
.withCopyToContainer(Transferable.of("test"), "/tmp/test")
.waitingFor(new WaitForExitedState(state -> state.getExitCodeLong() > 0))
.withCommand("sh", "-c", "grep -q test /tmp/test && exit 100")
Setting file mode is also possible.
GenericContainer<?> container = new GenericContainer<>(TestImages.TINY_IMAGE)
.withStartupCheckStrategy(new NoopStartupCheckStrategy())
.withCopyToContainer(Transferable.of("test", 0777), "/tmp/test")
.waitingFor(new WaitForExitedState(state -> state.getExitCodeLong() > 0))
.withCommand("sh", "-c", "ls -ll /tmp | grep '\\-rwxrwxrwx\\|test' && exit 100")
container.copyFileFromContainer(directoryInContainer + fileName, destinationOnHost);
| Web Proxy Viewer | New URL | Original Page |