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

时间:2018-08-27 21:19:37

标签: node.js docker

我是docker的新手,出于学习的目的,我遵循the official nodejs docker instructons并遵循了说明,但是在同一命令上始终会出错。

尝试按照64位弓docker的Ubuntu 18.04 Bionic beaver官方存储库安装中的说明重新安装整个amd64,但仍然出现相同的错误。

sudo的权限已授予npmdocker。在没有docker的情况下运行npmsudo *在终端中使用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

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

就我而言,package.json 中有一个错误,这就是为什么没有工作并抛出相同错误的原因。