gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:49:17 29 4
gpt4 key购买 nike

我正在尝试使用 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com