'How to use copyFileFromContainer?
I can't seem to get a file from the container. I've tried the following:
NETWORK = Network.newNetwork();
protected static GenericContainer<?> getpics = new GenericContainer<>(DockerImageName.parse(GETPICS_IMAGE))
.withNetwork(NETWORK).withNetworkAliases("getpics").withExposedPorts(8080).withEnv(getpicsEnv).withTmpFs(getpicsTempFs).withStartupTimeout(Duration.ofSeconds(300));
I used following loop to debug:
Scanner myObj = new Scanner(System.in);
while (true)
{
System.out.println("Search path: ");
String searchPath = "/data/pics";
searchPath = myObj.nextLine();
System.out.println("result path: ");
String outputPath = "/results";
outputPath = myObj.nextLine();
try
{
getpics.copyFileFromContainer(searchPath, outputPath);
}
catch (Exception e)
{
System.out.println(e);
}
I've tried following paths:
./data//pics/2021/5/17/A_A-W12-20220420-00001/1d87007d-5b28-4238-ab06-400e4149b249.jpg
/data//pics/2021/5/17/A_A-W12-20220420-00001/1d87007d-5b28-4238-ab06-400e4149b249.jpg
./pics/2021/5/17/A_A-W12-20220420-00001/1d87007d-5b28-4238-ab06-400e4149b249.jpg
/pics/2021/5/17/A_A-W12-20220420-00001/1d87007d-5b28-4238-ab06-400e4149b249.jpg
Error message:
com.github.dockerjava.api.exception.NotFoundException: Status 404: {"message":"Could not find the file ./data//pics/2021/5/17/A_A-W12-20220420-00001/1d87007d-5b28-4238-ab06-400e4149b249.jpg in container 90b74e10fc82681cea4e7a9459dd6bb4a95e7c212948d2599af09b90abe2bc8a"}
File is being inserted per post request. I've checked the file path manually upon entry to the container with /bin/bash (.find -name 1d87007d-5b28-4238-ab06-400e4149b249.jpg) and got the following result:
./pics/2021/5/17/A_A-W12-20220420-00001/1d87007d-5b28-4238-ab06-400e4149b249.jpg Testcontainers searches the correct container, so that's not the problem.
I can read the file without sudo, but I am still unsure whether or not this could be a permission problem. Where is the root of this search is located? Is it in the running container, or in the container image?
#Update 1: Files in /data are being found, but files in /data/pics not.
#Update 2: Content of getpicsTempFs
static final Map<String, String> getpicsTempFs = new HashMap<>();
static
{
getpicsEnv.put("SPRING_PROFILE", "test");
getpicsTempFs.put("/data/pics", "rw");
getpicsTempFs.put("/data/legacy", "rw");
}
Solution 1:[1]
I circumvent this problem by copying the file via
getpics.execInContainer("cp", filelocation, "/data");
getpics.copyFileFromContainer("data/" + imageName + ".jpg", inputStream -> {
String output = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
return null;
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Oskar Zdrojewski |
