我在docker上安装bcrypt时遇到问题。
我的节点应用程序需要bcrypt来加密用户数据。我使用npm install bcrypt --save
安装在本地计算机上,似乎运行良好。现在,我想对我的应用程序进行泊坞窗处理。
我的Dockerfile看起来像这样。
FROM node:10.12.0
RUN npm install --global node-pre-gyp
RUN apt-get update && apt-get install -y build-essential && apt-get install -y python && npm install
RUN mkdir -p /usr/src/app
RUN whoami
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install nodemon -g --save
RUN npm install
RUN node -v
RUN npm install bcrypt -g --save
# RUN npm install bcrypt - g --save
# CMD [ 'pm2', 'start', 'app.js' '--log-date-format' "'YYYY-MM-DD HH:mm Z'" ]
CMD [ "nodemon" ]
我的package.json文件如下:
{
"name": "api",
"version": "1.0.0",
"description": "Best app",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "name",
"license": "ISC",
"dependencies": {
"bcrypt": "^3.0.2",
"config": "^2.0.1",
"dotenv": "^6.1.0",
"express": "^4.16.4",
"joi": "^14.0.0",
"joi-objectid": "^2.0.0",
"jsonwebtoken": "^8.3.0",
"lodash": "^4.17.11",
"mongoose": "^5.3.4",
"multer": "^1.4.1",
"nodemailer": "^4.7.0",
"nodemon": "^1.18.4",
"stripe": "^6.15.0"
}
}
当我尝试使用docker build .
发生此错误:
Sending build context to Docker daemon 226 MB
Step 1/12 : FROM node:10.12.0
---> a2b9536415c2
Step 2/12 : RUN npm install --global node-pre-gyp
---> Using cache
---> c76403d98dd5
Step 3/12 : RUN apt-get update && apt-get install -y build-essential && apt-get install -y python && npm install
---> Using cache
---> 7926c2a74e90
Step 4/12 : RUN mkdir -p /usr/src/app
---> Using cache
---> 5ecb4eb08f05
Step 5/12 : RUN whoami
---> Using cache
---> e5ff9b23c652
Step 6/12 : WORKDIR /usr/src/app
---> Using cache
---> d0f9dd01719b
Step 7/12 : COPY . /usr/src/app
---> 30d30749e5d4
Removing intermediate container a20cfaca9bb3
Step 8/12 : RUN npm install nodemon -g --save
---> Running in a495bc73977f
/usr/local/bin/nodemon -> /usr/local/lib/node_modules/nodemon/bin/nodemon.js
> nodemon@1.18.7 postinstall /usr/local/lib/node_modules/nodemon
> node bin/postinstall || exit 0
Love nodemon? You can now support the project via the open collective:
> https://opencollective.com/nodemon/donate
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/nodemon/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
+ nodemon@1.18.7
added 223 packages from 130 contributors in 12.461s
---> 9bb36a08bd55
Removing intermediate container a495bc73977f
Step 9/12 : RUN npm install
---> Running in f544752d8d41
npm WARN api@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
audited 2580 packages in 3.287s
found 1 critical severity vulnerability
run `npm audit fix` to fix them, or `npm audit` for details
---> 5982d518a0e8
Removing intermediate container f544752d8d41
Step 10/12 : RUN node -v
---> Running in a08d0492d376
v10.12.0
---> c41e54a1910c
Removing intermediate container a08d0492d376
Step 11/12 : RUN npm install bcrypt -g --save
---> Running in 874f9d8d7bcf
> bcrypt@3.0.2 install /usr/local/lib/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Pre-built binaries not installable for bcrypt@3.0.2 and node@10.12.0 (node-v64 ABI, glibc) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/lib'
gyp WARN EACCES user "undefined" does not have permission to access the dev dir "/root/.node-gyp/10.12.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/bcrypt/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/bcrypt/.node-gyp'
gyp ERR! System Linux 4.15.0-42-generic
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/usr/local/lib/node_modules/bcrypt/lib/binding" "--napi_version=3" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v64"
gyp ERR! cwd /usr/local/lib/node_modules/bcrypt
gyp ERR! node -v v10.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/usr/local/lib/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64' (1)
node-pre-gyp ERR! stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/bcrypt/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:182:13)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:962:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
node-pre-gyp ERR! System Linux 4.15.0-42-generic
node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/bcrypt/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /usr/local/lib/node_modules/bcrypt
node-pre-gyp ERR! node -v v10.12.0
node-pre-gyp ERR! node-pre-gyp -v v0.11.0
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/local/lib/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/usr/local/lib/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v64' (1)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt@3.0.2 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt@3.0.2 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-12-07T15_41_19_990Z-debug.log
The command '/bin/sh -c npm install bcrypt -g --save' returned a non-zero code: 1
这在我本地的ubuntu 18.04上可以找到,但在docker上却找不到。 知道什么地方错了吗?