Hi, as title says - I'm using a withClasspathResourceMapping functionality, and as I can see - library copies empty file to container filesystem
I've made a small reproducible example here https://github.com/IgorPerikov/testcontainers-file-issue
steps to reproduce:
docker ps -adocker export your_container_name > ~/log.tar/tmp/myfileI've checked it with 1.6.0 and 1.5.1 versions, both copies empty file
➜ ~ docker -v
Docker version 17.12.0-ce, build c97c6d6
Hello, @rnorth @bsideup! Can you provide any help here, please?
Hi @IgorPerikov,
Sure, let me take a look. Also, @rnorth is out file system ninja, maybe he has some ideas :)
... and thank a lot for the demo repo 👍
@IgorPerikov I just tried and it worked on my machine (macOS, Docker for Mac)
Try this patch:
Index: src/test/java/com/github/igorperikov/issue/MovingFileToContainerTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/test/java/com/github/igorperikov/issue/MovingFileToContainerTest.java (revision 62929eaeb02fcb592f069322d64a03739a51a632)
+++ src/test/java/com/github/igorperikov/issue/MovingFileToContainerTest.java (date 1519997751000)
@@ -1,6 +1,10 @@
package com.github.igorperikov.issue;
+import com.github.dockerjava.api.DockerClient;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.io.IOUtils;
import org.junit.Test;
+import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
@@ -9,9 +13,17 @@
.withClasspathResourceMapping("myfile", "/tmp/myfile", BindMode.READ_ONLY);
@Test
- public void justToMakeADebugPoint() {
+ public void justToMakeADebugPoint() throws Exception {
container.start();
System.out.println("I'm up");
- container.stop();
+
+ DockerClient client = DockerClientFactory.instance().client();
+
+ try (TarArchiveInputStream tar = new TarArchiveInputStream(client.copyArchiveFromContainerCmd(container.getContainerId(), "/tmp/myfile").exec())) {
+ tar.getNextEntry();
+ String content = IOUtils.toString(tar);
+
+ assert content.startsWith("this\nis");
+ }
}
}
Also, what OS and method (docker-machine, Docker for Mac/Windows, native) are you using?
Test with this patch is passed. But when I verify it's content with docker export it still says that the file is empty.
Right now I've tested it with Ubuntu 14.04.5 LTS
My previous runs was at Ubuntu 16.04.? LTS
Speaking about method - I don't know how to answer for this part of question
@IgorPerikov on Linux it's "native" (no virtualization involved) :)
https://docs.docker.com/engine/reference/commandline/export/#parent-command
The docker export command does not export the contents of volumes associated with the container. If a volume is mounted on top of an existing directory in the container, docker export will export the contents of the underlying directory, not the contents of the volume.
that's why you're not seeing it I suppose :) But the file is there as you can see from my version of the test
Oh, that's why. Thanks for your help
@IgorPerikov always welcome :)