Docker 收到错误 FATAL EISDIR:对目录进行非法操作,请阅读

Docker getting error FATAL EISDIR: illegal operation on a directory, read

我在 docker 容器上尝试 运行 NPM 时偶然发现了这个错误。

 FATAL  EISDIR: illegal operation on a directory, read                                                                                      19:05:13

  at Object.readSync (node:fs:723:3)
  at tryReadSync (node:fs:433:20)
  at Object.readFileSync (node:fs:479:19)
  at loadEnv (node_modules/@nuxt/config/dist/config.js:1152:78)
  at Object.loadNuxtConfig (node_modules/@nuxt/config/dist/config.js:1070:15)
  at loadNuxtConfig (node_modules/@nuxt/cli/dist/cli-index.js:338:32)
  at NuxtCommand.getNuxtConfig (node_modules/@nuxt/cli/dist/cli-index.js:463:26)
  at Object.run (node_modules/@nuxt/cli/dist/cli-start.js:115:30)
  at NuxtCommand.run (node_modules/@nuxt/cli/dist/cli-index.js:413:22)

So in my case npm install worked just fine....when you try to run the app with npm run start your greeted with the above error.

不是什么:

  • 文件权限问题 - 是 运行 作为 root
  • 命令
  • .npmrc同目录或用户目录问题

解决方案

将所有 python 虚拟环境文件夹添加到 .dockerignore 在我的例子中,我什至没有将虚拟环境文件夹复制到我的 docker 容器。它的存在是导致问题的原因。

例子

.docker忽略

/api/.env

这很奇怪,我不知道为什么会这样......但我花了几天时间试图弄清楚为什么我的构建在部署时有效但在本地不起作用 - python 虚拟环境在部署期间被忽略,因此它们在云构建期间从未出现过,这就是它起作用的原因。

这里有更多关于这个问题的资源,但是这些对我不起作用: