如何使用copyfileflomcontainer?

发布于 2025-01-27 09:53:20 字数 2307 浏览 3 评论 0原文

我似乎无法从容器中获取文件。我已经尝试了以下操作:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛夏尉蓝 2025-02-03 09:53:20

我通过复制文件来解决此问题

getpics.execInContainer("cp", filelocation, "/data");
getpics.copyFileFromContainer("data/" + imageName + ".jpg", inputStream -> {
String output = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
        return null;
      });

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;
      });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文