命令'/ bin / sh -c npm install'返回非零代码:1

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了命令'/ bin / sh -c npm install'返回非零代码:1相关的知识,希望对你有一定的参考价值。

我是docker的新手,为了我的学习目的,我跟着the official nodejs docker instructons并按照说明操作,但它仍然在同一个命令上抛出错误。

尝试重新安装整个docker,正如Ubuntu 18.04仿生海狸的官方存储库安装中提到的拱形amd64 64位,但仍然得到相同的错误。

sudo权限已被授予npmdocker。运行dockernpm没有sudo *运行npm install工作正常在终端使用

Dockerfile

FROM node:8
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080
CMD [ "npm", "start" ]

错误

Sending build context to Docker daemon  19.46kB
Step 1/7 : FROM node:8
---> 55791187f71c
Step 2/7 : WORKDIR /usr/src/app
---> Using cache
---> 440112b72584
Step 3/7 : COPY package*.json ./
---> Using cache
---> 956513348aa7
Step 4/7 : RUN npm install
---> Running in dbbf0bc0d749
npm WARN hello@1.0.0 No repository field.

npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/array-flatten/-/array- 
flatten-1.1.1.tgz failed, reason: getaddrinfo EAI_AGAIN 
registry.npmjs.org:443

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2018-08-27T20_59_09_800Z-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 1

Docker版本和信息

Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:24:51 2018
 OS/Arch:           linux/amd64
 Experimental:      false
Server:
 Engine:
 Version:          18.06.1-ce
 API version:      1.38 (minimum version 1.12)
 Go version:       go1.10.3
 Git commit:       e68fc7a
 Built:            Tue Aug 21 17:23:15 2018
 OS/Arch:          linux/amd64
 Experimental:     false
答案

同样的问题,显然COPY package*.json ./命令没有正常工作。

我在安装NPM依赖项之前解决了这个复制文件的问题:

FROM node:8.15.1-alpine as build-stage
WORKDIR /app
COPY . .
RUN npm --verbose install
RUN npm run build

以上是关于命令'/ bin / sh -c npm install'返回非零代码:1的主要内容,如果未能解决你的问题,请参考以下文章

centos7中启动tomcat提示bash: tomcat8.0.39/bin/startup.sh: 权限不够

WSL2 节点:npm install cpu-features -> npm ERR! /bin/sh: 1: cmake: 权限被拒绝

解决npm ERR! Unexpected end of JSON input while parsing near '...sh_time":141072930277'

解决npm ERR! Unexpected end of JSON input while parsing near '...sh_time":141072930277'

sh NPM命令

sh #npm更新命令