问题描述
错误! [email protected] build:ssr: ng build --prod && ng run ssf:server:production
npm ERR!退出状态 1
请在下面找到我的 Docker 文件
FROM node:10.16.3-slim AS build
workdir /app
copY ./package.json ./package-lock.json /app/
RUN npm install
copY . /app
ENV NODE_OPTIONS --max-old-space-size=4096
RUN npm run build:ssr **(Error is coming at this line)**
copY --from=build /app/package.json /app
copY --from=build /app/dist /app/dist
EXPOSE 4000
ENV NODE_ENV production
CMD ["npm","run","serve:ssr"]
另外,这是 package.json 快照
{
"name": "ssf","version": "0.0.0","scripts": {
"ng": "ng","start": "ng serve","build": "ng build","test": "ng test","lint": "ng lint","e2e": "ng e2e","dev:ssr": "ng run ssf:serve-ssr","serve:ssr": "node dist/server/main.js","build:ssr": "ng build --prod && ng run ssf:server:production","prerender": "ng run ssf:prerender"
},
解决方法
我不确定这是否仍然相关..但您可以尝试用以下内容替换您的 dockerfile:
### Stage: 1 ###
FROM node:14-alpine as Build
WORKDIR /app
COPY ./package.json ./package-lock.json /app/
RUN npm install
COPY . /app
#This will create dist/ and dist-server/ folders in docker
RUN npm run build:ssr
### Stage: 2 ###
FROM node:14-alpine
WORKDIR /app
COPY --from=Build /app/package.json /app
COPY --from=Build /app/dist /app/dist
COPY --from=Build /app/dist/server /app/dist-server
EXPOSE 4000
CMD ["npm","run","serve:ssr"]
我仍在自己测试这个,但我已经成功运行了这个容器。 希望这能帮助您或其他人阅读本文。
亲切的问候, R