【问题标题】:Deno : Writing to CSV files on a Docker Container ( Permission denied (os error 13) )Deno:写入 Docker 容器上的 CSV 文件(权限被拒绝(操作系统错误 13))
【发布时间】:2020-09-30 14:31:13
【问题描述】:

我正在了解 Deno 的问题,但我在使用 Deno writeCSV() 实用程序写入 CSV 文件时遇到权限问题。我已经搭建了项目以在顶级 Docker 上运行

Dockerfile

CMD ["run", "--allow-read", "--allow-run", "--allow-write", "--allow-net", "main.ts"]

Main.ts


import { serve, readCSV, writeCSV } from "./deps.ts";

const URL = "https://www.getcats.com/api"
const DEFAULT_PRODUCT_ID = "xxxxxxxxxxxx";
const DEFAULT_DESCRIPTION = "Description";
const options = {
  method: "POST",
  url: URL,
  body: {},
  headers: {
    "x-api-key": "xxxxxxxxxxxxx"
  },
  json: true // Automatically stringifies the body to JSON
};

// CSV File Properties
const f = await Deno.open("./inbound/example.csv");
const outputFile = await Deno.open("./outbound/outbound.csv", { write: true, create: true, read: true, truncate: true });

for await (const row of readCSV(f)) {
  for await (const cell of row) {
    queueMicrotask(async () => {

      const response = await fetch(URL, {
        method: "POST",
        headers: {
          'content-type': 'application/json',
          "x-api-key": "xxxxxxxxxxxxxxx"
        },
        body: JSON.stringify({
          memberId: cell,
          productId: DEFAULT_PRODUCT_ID,
          description: DEFAULT_DESCRIPTION
        }),
      });

      response.json()
        .then(async (res)=> {
          const data = res.data;
          const memberId = data.memberId;
          const hashId = data.id;
          const rows = [memberId, hashId]
          console.log(`CAT ID: ${memberId} - HASH ID: ${hashId}`);                

          await writeCSV(outputFile, rows);
          outputFile.close();

        })

    })

  }
}
f.close();

我假设在运行容器时发送 ---allow-write 可以解决这个烫发问题。还有其他人在通过 Docker 写入 Deno 中的目录时遇到问题吗?

【问题讨论】:

  • 如果你使用 -A 开关代替所有这些会发生什么?
  • 你使用的是什么版本的 Deno?
  • - 运行:deno 1.0.0, v8 8.4.300 , typescript 3.9.2 - 我确实尝试使用 -A 命令运行它,但没有成功
  • @victorpalma 显示你的deps.ts 文件,我需要查看依赖项。
  • 它只是从 Deno 库中导出:export { serve } from "deno.land/std@0.50.0/http/server.ts";从“deno.land/x/csv/mod.ts”导出 { readCSV, writeCSV };

标签: node.js docker deno


【解决方案1】:

您能否从博客here. 中查看非常相似问题的解决方案建议

这里是简单的问题描述:

我遇到的一件事是,最初,Dockerfile 指定了一个 具有有限权限的用户。这引发了一个非常神秘的异常:

error: Uncaught PermissionDenied: Permission denied (os error 13)
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
    at Object.listen ($deno$/ops/net.ts:51:10)
    at listen ($deno$/net.ts:152:22)
    at serve (https://deno.land/std@0.50.0/http/server.ts:261:20)
    at file:///app/main.ts:4:11

这是一个解决方案:

事实证明,这是因为我们希望在 port 80Non-privileged user(非根)can't open a listening socket on ports below 1024。确保 运行该进程的用户(可以使用 USER in 指定 your Dockerfile) has enough permission。在我们的例子中,只需 omitting USER 工作正常。

这里还有一个solution 示例。

【讨论】:

  • 是的,这不是问题。 Deno 告诉我以下行失败: const outputFile = await Deno.open("./outbound/outbound.csv", { write: true, create: true, read: true, truncate: true });跨度>
猜你喜欢
  • 1970-01-01
  • 2023-02-14
  • 2015-02-19
  • 1970-01-01
  • 2021-03-05
  • 2022-09-27
  • 2021-07-11
  • 1970-01-01
  • 2020-07-04
相关资源
最近更新 更多