docker 容器中的 NPM 安装失败并返回“命令 '/bin/sh -c npm install' 返回非零代码:1" [英] NPM install in docker container fails and returns "The command '/bin/sh -c npm install' returned a non-zero code: 1"

查看:89
本文介绍了docker 容器中的 NPM 安装失败并返回“命令 '/bin/sh -c npm install' 返回非零代码:1"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 gitlab CI/CD 将我的 dockerized MERN 堆栈 Web 应用程序部署到我的 vps.在我的 react 应用 dockerfile 中,当我尝试安装 npm 包时,出现此错误:

I'm trying to deploy my dockerized MERN stack web app to my vps with gitlab CI/CD. In my react app dockerfile, when I try to install npm packages, I get this error:

服务nowfront"无法构建:命令/bin/sh -c npm install"返回非零代码:1

这是我的 Dockerfile:

This is my Dockerfile:

# pull official base image
FROM node as builder

# make directory
RUN mkdir -p /app
RUN chmod -R 777 /app

# set working directory
WORKDIR /app

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH

# install app dependencies
COPY package.json .
RUN npm install

# add app
COPY . .
COPY .env .
RUN ls -li
#RUN yarn build
#CMD ["npm","run","build"]
RUN ls

FROM nginx:stable-alpine
COPY --from=builder /app/build /usr/share/nginx/html 
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

我的 Ubuntu 版本是 20.04.1 LTS.

My Ubuntu version is 20.04.1 LTS.

有没有办法通过这个?

推荐答案

我更新了我的 Dockerfile 并添加了第 14 行,现在可以使用了.

I updated my Dockerfile and added line 14 and it works now.

# pull official base image
FROM node as builder

# make directory
RUN mkdir -p /app
RUN chmod -R 777 /app

# set working directory
WORKDIR /app

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH

# install app dependencies
COPY package.json .
COPY package-lock.json .
RUN npm install

# add app
COPY . .
COPY .env .
RUN ls -li
#RUN yarn build
#CMD ["npm","run","build"]
RUN ls

FROM nginx:stable-alpine
COPY --from=builder /app/build /usr/share/nginx/html 
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

这篇关于docker 容器中的 NPM 安装失败并返回“命令 '/bin/sh -c npm install' 返回非零代码:1"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆