Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript docker节点js文件存储卷_Javascript_Node.js_Docker Api - Fatal编程技术网

Javascript docker节点js文件存储卷

Javascript docker节点js文件存储卷,javascript,node.js,docker-api,Javascript,Node.js,Docker Api,我制作了一个应用程序,可以下载图像并将其保存到名为storage的目录中。在开发过程中一切都很好,但在容器中我遇到了错误: {“errno”:-2,“code”:“enoint”,“syscall”:“open”,“path”:“/usr/src/app/src/storage/samsung-Galaxy-Note20-Ultra-thumboil.jpg”,“level”:“error”,“service”:“user-service”,“timestamp”:“2021-05-20T20:

我制作了一个应用程序,可以下载图像并将其保存到名为
storage
的目录中。在开发过程中一切都很好,但在容器中我遇到了错误:

{“errno”:-2,“code”:“enoint”,“syscall”:“open”,“path”:“/usr/src/app/src/storage/samsung-Galaxy-Note20-Ultra-thumboil.jpg”,“level”:“error”,“service”:“user-service”,“timestamp”:“2021-05-20T20:27:42.545Z”,“message”:“enoint:没有这样的文件或目录,打开“/usr/src/app/src/storage/samsung-Galaxy-Note20-Ultra-thumboil.jpg”,“stack”:”“错误:enoint:没有这样的文件或目录,请打开'/usr/src/app/src/storage/samsung-Galaxy-Note20-Ultra-thumbnail.jpg'”

这是我的下载代码:

    for (const [i, product] of products.entries()) {
      const { thumbnail, name } = product;
      const ext = thumbnail.slice(thumbnail.lastIndexOf("."));
      const filePath = `${path.resolve("./src/storage")}/${
        brand.text
      }-${slugify(name)}-thumbnail${ext}`;

      try {
        await download({
          url: thumbnail,
          path: filePath,
        });
        products[i].thumbnail = filePath.slice(filePath.indexOf("src"));

        logger.info(`"${name}" thumbnail saved to ${filePath}`);
      } catch (error) {
        logger.error(error);
      }
    }
此代码使用
路径
节点js模块,这是下载功能:

const { createWriteStream } = require("fs");
const { pipeline } = require("stream");
const { promisify } = require("util");
const fetch = require("node-fetch");

const download = async ({ url, path }) => {
  const streamPipeline = promisify(pipeline);
  const response = await fetch(url);

  if (!response.ok) {
    throw new Error(`unexpected response ${response.statusText}`);
  }

  await streamPipeline(response.body, createWriteStream(path));
};
这是我的文件夹结构:

以及docker-comspoe.yml中的我的docker卷:

   volumes:
      - ./storage:/src/storage
和dockerfile中的工作目录:

WORKDIR /usr/src/app

我不知道是什么原因导致了这个错误。

您正在安装dir
/src/storage
,但正在上载到
/usr/src/app/src/storage/

更改为:

`${path.resolve("./src/storage")}/${brand.text}-${slugify(name)}-thumbnail${ext}`;
致:


这是Windows/MacOS吗?linux上MacOS产品的开发VPSI做到了这一点,它在docker容器中工作得很好,但在MacOS中失败了。我改为
path.join(\uu dirname,../storage')
,效果很好。但卷不工作(并且没有错误)。
`${path.resolve("/src/storage")}