如何使用copyfileflomcontainer?
我似乎无法从容器中获取文件。我已经尝试了以下操作:
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));
我使用以下循环进行调试:
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);
}
我尝试了以下路径:
.//data//pics /2021/5/17/a_a_a_a_a_a_a_a_a_a_a-w12-20220420420-00001/1d87007007d-5b28-4238-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要求。我在输入/bin/bash(.find -name 1D87007D-5B28-4238-4238-428-428-428-400E414149B249.JPG)时手动检查了文件路径,并得到以下结果:
./ 2021/5/17 /A_A-W12-20220420-00001/1D87007D-5B28-4238-AB06-400E4149B249.JPG TestContainers搜索正确的容器,因此这不是问题。
我可以在没有sudo的情况下阅读该文件,但是我仍然不确定这是否是一个许可问题。 此搜索的根源在哪里?是在运行的容器中还是在容器图像中?
#update 1: 正在找到 /数据中的文件,但是 /数据 /图片中的文件却没有。
#update 2: 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");
}
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");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过复制文件来解决此问题
I circumvent this problem by copying the file via