简体   繁体   English

Angular 通用 Docker 构建问题

[英]Issue with Angular Universal Docker build

When I'm trying to build my Docker file, I'm getting the below error当我尝试构建我的 Docker 文件时,出现以下错误

ERROR in Cannot read property '0' of undefined无法读取未定义的属性“0”中的错误

npm ERR! npm 错误! code ELIFECYCLE代码生命周期

npm ERR! npm 错误! errno 1 npm错误号 1 npm

ERR.呃。 ssf@0.0:0 build:ssr: ng build --prod && ng run ssf:server:production npm ERR! ssf@0.0:0 build:ssr: ng build --prod && ng run ssf:server:production npm ERR! Exit status 1退出状态 1

Please find below my Docker file请在下面找到我的 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"]

Also, this is the package.json snapshot此外,这是 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"
    
  },

I'm not sure if this is still relevant.. but you can try replacing your dockerfile with the following:我不确定这是否仍然相关..但您可以尝试用以下内容替换您的 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"]

I'm still testing this myself but I successfully run this container already.我自己还在测试这个,但我已经成功运行了这个容器。 Hope this will help you or others reading this.希望这会帮助您或其他阅读本文的人。

Kind regards, R亲切的问候, R

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

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