【问题标题】:Issue with Angular Universal Docker buildAngular Universal Docker 构建的问题
【发布时间】:2021-05-17 14:50:10
【问题描述】:

当我尝试构建 Docker 文件时,出现以下错误

无法读取未定义的属性“0”时出现错误

npm 错误!代码生命周期

npm 错误!错误号 1 npm

错误! ssf@0.0.0 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"
    
  },

【问题讨论】:

    标签: angular docker universal


    【解决方案1】:

    我不确定这是否仍然相关.. 但您可以尝试将 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"]
    

    我自己还在测试这个,但我已经成功运行了这个容器。 希望这会帮助您或其他阅读本文的人。

    亲切的问候, 回复

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      • 2021-02-15
      相关资源
      最近更新 更多