繁体   English   中英

NPM 安装在 docker 容器中失败并返回“命令'/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”

我正在尝试使用 gitlab CI/CD 将我的 dockerized MERN 堆栈 web 应用程序部署到我的 vps。 在我的反应应用 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;"]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM