如何解决 docker 与 /bin/sh 相关的问题:node-pre-gyp: not found?
How to solve docker related issue with /bin/sh: node-pre-gyp: not found?
一天前我开始自学Docker。所以我将应用程序下载到我的 Windows 10 桌面,并通过应用程序开始了他们推荐的教程。有一次他们要求我创建一个包含以下内容的 docker 文件:
FROM node:12-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "/app/src/index.js"]
我在名称 "Dockerfile" 下对路径 D:\docker_stuff\app
所做的,没有扩展名。接下来他们让我 运行 这个命令 "docker build -t getting-started ." 这是我遇到问题的地方,因为命令抛出如下错误:
D:\docker_stuff\app>docker build -t getting-started .
Sending build context to Docker daemon 4.673MB
Step 1/5 : FROM node:12-alpine
---> 7a48db49edbf
Step 2/5 : WORKDIR D:\docker_stuff\app
---> Using cache
---> 44ba6501de00
Step 3/5 : COPY . .
---> 44164775d408
Step 4/5 : RUN yarn install --production
---> Running in 5df554d6bac8
yarn install v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
error /D:docker_stuffapp/node_modules/bcrypt: Command failed.
Exit code: 127
Command: node-pre-gyp install --fallback-to-build
Arguments:
Directory: /D:docker_stuffapp/node_modules/bcrypt
Output:
/bin/sh: node-pre-gyp: not found
我尝试了什么:
- 已安装的节点
D:\docker_stuff\app>node -v
v12.16.3;
- 已安装 npm
D:\docker_stuff\app>npm -v
6.14.4;
- 运行 独立命令:node-pre-gyp install --fallback-to-build 会引发更多问题:
D:\docker_stuff\app>node-pre-gyp install --fallback-to-build
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@0.14.0
node-pre-gyp info using node@12.16.3 | win32 | x64
node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp ERR! install error
node-pre-gyp ERR! stack Error: 101-app package.json is not node-pre-gyp ready:
node-pre-gyp ERR! stack package.json must declare these properties:
node-pre-gyp ERR! stack binary.module_name
node-pre-gyp ERR! stack binary.module_path
node-pre-gyp ERR! stack binary.host
node-pre-gyp ERR! stack at validate_config (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\lib\util\versioning.js:220:15)
node-pre-gyp ERR! stack at Object.module.exports.evaluate (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\lib\util\versioning.js:279:5)
node-pre-gyp ERR! stack at install (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\lib\install.js:241:31)
node-pre-gyp ERR! stack at Object.self.commands.<computed> [as install] (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\lib\node-pre-gyp.js:52:37)
node-pre-gyp ERR! stack at run (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\bin\node-pre-gyp:82:30)
node-pre-gyp ERR! stack at Object.<anonymous> (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\bin\node-pre-gyp:134:1)
node-pre-gyp ERR! stack at Module._compile (internal/modules/cjs/loader.js:1133:30)
node-pre-gyp ERR! stack at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
node-pre-gyp ERR! stack at Module.load (internal/modules/cjs/loader.js:977:32)
node-pre-gyp ERR! stack at Function.Module._load (internal/modules/cjs/loader.js:877:14)
node-pre-gyp ERR! System Windows_NT 10.0.18363
node-pre-gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\bin\node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd D:\docker_stuff\app
node-pre-gyp ERR! node -v v12.16.3
node-pre-gyp ERR! node-pre-gyp -v v0.14.0
node-pre-gyp ERR! not ok
101-app package.json is not node-pre-gyp ready:
package.json must declare these properties:
binary.module_name
binary.module_path
binary.host
修改了 git 项目中的 package.json 文件,我在 [=61= 下添加了行 <"bcrypt": "^3.0.6",> ]: { ;
Python 已安装。
我觉得 package.json 文件可能有问题,而不是我的桌面,但我不确定,如果那是问题,我该如何解决?我知道我是菜鸟,但谁能给我一些指导?
"bcrypt": "^3.0.6"
需要安装 python 并且您在 Dockerfile node:12-alpine
中使用的图像是 nodejs 的非常小的图像。
您可以使用 ubuntu 图像并将 python 安装到您正在构建的容器中,或者您可以使用 bcryptjs 代替。
您可以添加 <"bcryptjs": "^2.4.3",> 或仅添加 运行 npm i bcryptjs
.
它在 bcyptjs
的 README.md
上说它会比 bcrypt
慢 30% 但你不必担心 python 对你的依赖应用
我将 zone.js
从 0.10.3
升级到 0.11.0
,我遇到了这个问题,恢复后解决了我的问题。
一天前我开始自学Docker。所以我将应用程序下载到我的 Windows 10 桌面,并通过应用程序开始了他们推荐的教程。有一次他们要求我创建一个包含以下内容的 docker 文件:
FROM node:12-alpine
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "/app/src/index.js"]
我在名称 "Dockerfile" 下对路径 D:\docker_stuff\app
所做的,没有扩展名。接下来他们让我 运行 这个命令 "docker build -t getting-started ." 这是我遇到问题的地方,因为命令抛出如下错误:
D:\docker_stuff\app>docker build -t getting-started .
Sending build context to Docker daemon 4.673MB
Step 1/5 : FROM node:12-alpine
---> 7a48db49edbf
Step 2/5 : WORKDIR D:\docker_stuff\app
---> Using cache
---> 44ba6501de00
Step 3/5 : COPY . .
---> 44164775d408
Step 4/5 : RUN yarn install --production
---> Running in 5df554d6bac8
yarn install v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
error /D:docker_stuffapp/node_modules/bcrypt: Command failed.
Exit code: 127
Command: node-pre-gyp install --fallback-to-build
Arguments:
Directory: /D:docker_stuffapp/node_modules/bcrypt
Output:
/bin/sh: node-pre-gyp: not found
我尝试了什么:
- 已安装的节点
D:\docker_stuff\app>node -v
v12.16.3;
- 已安装 npm
D:\docker_stuff\app>npm -v
6.14.4;
- 运行 独立命令:node-pre-gyp install --fallback-to-build 会引发更多问题:
D:\docker_stuff\app>node-pre-gyp install --fallback-to-build
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@0.14.0
node-pre-gyp info using node@12.16.3 | win32 | x64
node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp ERR! install error
node-pre-gyp ERR! stack Error: 101-app package.json is not node-pre-gyp ready:
node-pre-gyp ERR! stack package.json must declare these properties:
node-pre-gyp ERR! stack binary.module_name
node-pre-gyp ERR! stack binary.module_path
node-pre-gyp ERR! stack binary.host
node-pre-gyp ERR! stack at validate_config (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\lib\util\versioning.js:220:15)
node-pre-gyp ERR! stack at Object.module.exports.evaluate (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\lib\util\versioning.js:279:5)
node-pre-gyp ERR! stack at install (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\lib\install.js:241:31)
node-pre-gyp ERR! stack at Object.self.commands.<computed> [as install] (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\lib\node-pre-gyp.js:52:37)
node-pre-gyp ERR! stack at run (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\bin\node-pre-gyp:82:30)
node-pre-gyp ERR! stack at Object.<anonymous> (C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\bin\node-pre-gyp:134:1)
node-pre-gyp ERR! stack at Module._compile (internal/modules/cjs/loader.js:1133:30)
node-pre-gyp ERR! stack at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
node-pre-gyp ERR! stack at Module.load (internal/modules/cjs/loader.js:977:32)
node-pre-gyp ERR! stack at Function.Module._load (internal/modules/cjs/loader.js:877:14)
node-pre-gyp ERR! System Windows_NT 10.0.18363
node-pre-gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\KahnTrevor\AppData\Roaming\npm\node_modules\node-pre-gyp\bin\node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd D:\docker_stuff\app
node-pre-gyp ERR! node -v v12.16.3
node-pre-gyp ERR! node-pre-gyp -v v0.14.0
node-pre-gyp ERR! not ok
101-app package.json is not node-pre-gyp ready:
package.json must declare these properties:
binary.module_name
binary.module_path
binary.host
修改了 git 项目中的 package.json 文件,我在 [=61= 下添加了行 <"bcrypt": "^3.0.6",> ]: { ;
Python 已安装。
我觉得 package.json 文件可能有问题,而不是我的桌面,但我不确定,如果那是问题,我该如何解决?我知道我是菜鸟,但谁能给我一些指导?
"bcrypt": "^3.0.6"
需要安装 python 并且您在 Dockerfile node:12-alpine
中使用的图像是 nodejs 的非常小的图像。
您可以使用 ubuntu 图像并将 python 安装到您正在构建的容器中,或者您可以使用 bcryptjs 代替。
您可以添加 <"bcryptjs": "^2.4.3",> 或仅添加 运行 npm i bcryptjs
.
它在 bcyptjs
的 README.md
上说它会比 bcrypt
慢 30% 但你不必担心 python 对你的依赖应用
我将 zone.js
从 0.10.3
升级到 0.11.0
,我遇到了这个问题,恢复后解决了我的问题。