Node.js 命令'/垃圾箱/垃圾箱-c npm安装和维护&;npm ls';返回了一个非零代码:1

Node.js 命令'/垃圾箱/垃圾箱-c npm安装和维护&;npm ls';返回了一个非零代码:1,node.js,docker,Node.js,Docker,基本上我在努力生活。我对Docker也是个新手 我有一个现有的基于nodejs-express的API项目,我想转移到这个项目 以下是Dockerfile: FROM node:latest WORKDIR /code RUN npm install -g nodemon COPY package.json /code/package.json RUN npm install && npm ls RUN mv /code/node_modules /node_modules

基本上我在努力生活。我对Docker也是个新手

我有一个现有的基于nodejs-express的API项目,我想转移到这个项目

以下是Dockerfile:

FROM node:latest

WORKDIR /code

RUN npm install -g nodemon

COPY package.json /code/package.json
RUN npm install && npm ls
RUN mv /code/node_modules /node_modules

COPY . /code

CMD ["npm", "start"]
最后,
docker compose.yml

version: "2"

services:
  web:
    build: .
    command: nodemon --debug=5858
    volumes:
      - .:/code
    ports:
      - "8000:8000"
      - "5858:5858"
现在,当我使用docker compose up启动应用程序时,它会抛出以下错误:

Service 'web' failed to build: The command '/bin/sh -c npm install && npm ls' returned a non-zero code: 1
我已经试过了,但还是一样的问题

以下是docker build-t项目名称之后的完整堆栈跟踪。:

Sending build context to Docker daemon  360.9MB
Step 1/7 : FROM node:latest
 ---> 451b716593e5
Step 2/7 : WORKDIR /code
 ---> Using cache
 ---> b94de1bb15a2
Step 3/7 : RUN npm install -g nodemon
 ---> Using cache
 ---> 19fee55fb68b
Step 4/7 : COPY package.json /code/package.json
 ---> Using cache
 ---> ded2bb55f958
Step 5/7 : RUN npm install && npm ls
 ---> Running in 60c516514d02
npm WARN deprecated bcrypt@1.0.3: bcrypt < v2.0.0 is susceptible to bcrypt wrap-around bug. Upgrade to bcrypt >= v2.0.0 for improved support for newer bcrypt hashes
npm WARN deprecated boom@5.2.0: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated joi@13.7.0: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated hoek@4.2.1: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated hoek@5.0.4: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated topo@3.0.3: This module has moved and is now available at @hapi/topo. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated joi@6.10.1: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated hoek@6.1.3: This module has moved and is now available at @hapi/hoek. Please update your dependencies as this version is no longer maintained an may contain bugs and security issues.
npm WARN deprecated topo@1.1.0: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated hoek@2.16.3: This version has been deprecated in accordance with the hapi support policy (hapi.im/support). Please upgrade to the latest version to get the best features, bug fixes, and security patches. If you are unable to upgrade at this time, paid support is available for older versions (hapi.im/commercial).
npm WARN deprecated circular-json@0.3.3: CircularJSON is in maintenance only, flatted is its successor.
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()

> phantomjs-prebuilt@2.1.16 install /code/node_modules/phantomjs-prebuilt
> node install.js

PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...

Received 22866K total.
Extracting tar contents (via spawned process)
Removing /code/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1560259586773/phantomjs-2.1.1-linux-x86_64 -> /code/node_modules/phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /code/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs

> bcrypt@1.0.3 install /code/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! Tried to download(404): https://github.com/kelektiv/node.bcrypt.js/releases/download/v1.0.3/bcrypt_lib-v1.0.3-node-v72-linux-x64.tar.gz 
node-pre-gyp ERR! Pre-built binaries not found for bcrypt@1.0.3 and node@12.4.0 (node-v72 ABI) (falling back to source compile with node-gyp) 
node-pre-gyp ERR! Tried to download(undefined): https://github.com/kelektiv/node.bcrypt.js/releases/download/v1.0.3/bcrypt_lib-v1.0.3-node-v72-linux-x64.tar.gz 
node-pre-gyp ERR! Pre-built binaries not found for bcrypt@1.0.3 and node@12.4.0 (node-v72 ABI) (falling back to source compile with node-gyp) 
make: Entering directory '/code/node_modules/bcrypt/build'
  CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
make: Entering directory '/code/node_modules/bcrypt/build'
  CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
rm: cannot remove './Release/.deps/Release/obj.target/bcrypt_lib/src/blowfish.o.d.raw': No such file or directory
bcrypt_lib.target.mk:109: recipe for target 'Release/obj.target/bcrypt_lib/src/blowfish.o' failed
make: Leaving directory '/code/node_modules/bcrypt/build'
make: *** [Release/obj.target/bcrypt_lib/src/blowfish.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR!  CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o
 stack     at ChildProcess.emit (events.js:200:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Linux 4.9.125-linuxkit
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/code/node_modules/bcrypt/lib/binding/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/code/node_modules/bcrypt/lib/binding"
gyp ERR! cwd /code/node_modules/bcrypt
gyp ERR! node -v v12.4.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 build --fallback-to-build --module=/code/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/code/node_modules/bcrypt/lib/binding' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/code/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:200:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
node-pre-gyp ERR! System Linux 4.9.125-linuxkit
node-pre-gyp ERR! command "/usr/local/bin/node" "/code/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /code/node_modules/bcrypt
node-pre-gyp ERR! node -v v12.4.0
node-pre-gyp ERR! node-pre-gyp -v v0.6.36
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 build --fallback-to-build --module=/code/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/code/node_modules/bcrypt/lib/binding' (1)
Assembler messages:
Error: can't open /code/node_modules/bcrypt/ccwfjQgR.s for reading: No such file or directory
make: *** [Release/obj.target/bcrypt_lib/src/bcrypt.o] Error 1
bcrypt_lib.target.mk:109: recipe for target 'Release/obj.target/bcrypt_lib/src/bcrypt.o' failed
make: Leaving directory '/code/node_modules/bcrypt/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:200:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Linux 4.9.125-linuxkit
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/code/node_modules/bcrypt/lib/binding/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/code/node_modules/bcrypt/lib/binding"
gyp ERR! cwd /code/node_modules/bcrypt
gyp ERR! node -v v12.4.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN backend@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt@1.0.3 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the bcrypt@1.0.3 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/2019-06-11T13_26_35_611Z-debug.log
The command '/bin/sh -c npm install && npm ls' returned a non-zero code: 1
由于某些原因,它没有安装


有人知道这个问题的原因吗?

尝试单独运行
docker build
(而不是运行
docker compose up
)。您应该有更多关于失败步骤(
npm安装和&npm ls
)的日志。无法复制。对我来说非常有效。虽然你可能注意到了你的小问题。。。(当您将目录装载到
/code
时,
/code
中的所有内容都会被覆盖,包括刚刚安装的
节点\u模块……)我不认为这是导致当前问题的原因,但以后可能会给您带来麻烦。祝你好运cmd[“sh”、“-c”、“npm start”]@trungdang仍然存在相同的问题:(@norbjd
docker build-t project name.
导致相同的错误,但堆栈跟踪似乎提供了一些见解,可以单独运行
docker build
(而不是运行
docker compose
)。您应该有更多关于失败步骤(
npm安装和&npm ls
)的日志。无法复制。对我来说效果很好。尽管您可能注意到了一些小问题。。。(当您将目录装载到
/code
时,
/code
中的所有内容都会被覆盖,包括刚刚安装的
节点(node)模块
)我不认为这是导致当前问题的原因,但它可能会在以后给您带来麻烦。祝您好运cmd[“sh”、“-c”、“npm start”]@trungdang仍然存在相同的问题:(@norbjd
docker build-t project name.
导致相同的错误,但堆栈跟踪似乎提供了一些见解
npm install ajv@^2.1.1 --save