node.js - 命令“/bin/sh -c npm install”返回一个非零代码:1
问题描述
我是新手docker
,出于学习目的,我遵循了官方的 nodejs docker instructons并按照说明进行操作,但它不断在同一命令上抛出错误。
docker
尝试按照 Ubuntu 18.04 Bionic beaver for arch amd64
64 位的官方存储库安装中所述重新安装整体,但仍然出现相同的错误。
(sudo
权限已被授予npm
and docker
。docker
npm
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
推荐阅读
- jenkins - 如何在声明性管道中从 archiveArtifact 中排除文件?
- tensorflow - tensorflow 'ScatterNdUpdate' Op 要求输入 'ref' 是可变张量(例如:tf.Variable)
- jenkins - 主机重启后如何继续詹金斯管道。
- python - pandas 合并彼此相距不到 20 秒的交互
- c - Minifilter cause lag on disk management and system restore
- android - 如何从其他recyclerview接收recyclerview中的数据?
- macos - dispatch_get_main_queue crashes in a method called a second time
- ios - 如何验证国家代码和手机号码
- excel - data validation list based on checkbox value
- git - git remove old commits