node.js - docker 容器中的 NPM 安装失败并返回 "The command '/bin/sh -c npm install' 返回非零代码 : 1"

标签 node.js docker ubuntu npm bin

我正在尝试使用 gitlab CI/CD 将我的 dockerized MERN 堆栈 Web 应用程序部署到我的 vps。在我的 react 应用程序 dockerfile 中,当我尝试安装 npm 包时,出现此错误:
服务“nowfront”构建失败:命令“/bin/sh -c npm install”返回非零代码:1
这是我的 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。
有什么解决方案可以通过吗?

最佳答案

我更新了我的 Dockerfile 并添加了第 14 行,它现在可以工作了。

# 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;"]

关于node.js - docker 容器中的 NPM 安装失败并返回 "The command '/bin/sh -c npm install' 返回非零代码 : 1",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65396985/

相关文章:

templates - NodeJS + Express + Handlebars - 找不到 View "index.html"

docker - 在主机上挂载开发 docker 容器目录

docker - 提交一个Docker容器但没有任何更改

javascript - Angular 7 使用 ng build --prod 缩小 Assets

node.js - 如何避免 Mocha 测试用例超时?

mysql - 如何在 ubuntu 操作系统上启动 mysql 服务时导入 .sql 文件

ubuntu - 设置hadoop 3.2.0 伪分发运行报错

python - 如何在 Ubuntu 16.04 中创建 Python 3.8 虚拟环境

ubuntu - Ubuntu中简单时间线绘制的应用

node.js - 如何使用 Node.js 确定当前的操作系统