如何创建Angular Universal Dockerfile和docker-compose.yml文件



因此,我正在尝试将我的Angular通用应用程序Dockerize,以便将其与已经Dockerize的spring引导休息后端一起使用,我发现很难在互联网上获得一些帮助和资源。这里我有一个Angular universal的Dockerfile的例子,但尽管我做了一些更改,它对我来说还是不起作用

FROM node:12-alpine as buildContainer
WORKDIR /app
COPY ./package.json ./package-lock.json /app/
RUN npm install
COPY . /app
RUN npm run build:universal
# RUN npm run generate:pretender
RUN npm run test:ssr
FROM node:8-alpine
WORKDIR /app
# Copy dependency definitions
COPY --from=buildContainer /app/package.json /app
# COPY --from=buildContainer /app/server.js /app
# Get all the code needed to run the app
COPY --from=buildContainer /app/dist /app/dist
# COPY --from=buildContainer /app/static /app/static
COPY --from=buildContainer /app/dist-server /app/dist-server
# Expose the port the app runs in
EXPOSE 4200
# Serve the app
CMD ["npm", "run", "server"]

我正在用下面的命令docker build -t angular-universal .构建图像,但它在第六步失败,说

npm ERR!缺少脚本:生成:通用npm ERR!此运行的完整日志可在以下位置找到:npm ERR/root/.npm/\logs/2020-04-19T20_29_16_368Z-debug.log命令"/bin/sh-c npm run build:universal"返回了一个非零代码:1

有人有同样的问题吗?

这是我的包.json

{
"name": "jobnow",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve --host 0.0.0.0",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"deploy": "ng deploy --base-href=https://samgevorgyan.github.io/jobnow/"
},
"private": true,
"dependencies": {
"@angular/animations": "~9.0.1",
"@angular/cdk": "^9.0.0",
"@angular/common": "~9.0.1",
"@angular/compiler": "~9.0.1",
"@angular/core": "~9.0.1",
"@angular/flex-layout": "^9.0.0-beta.29",
"@angular/forms": "~9.0.1",
"@angular/material": "^9.0.0",
"@angular/material-moment-adapter": "^9.1.2",
"@angular/platform-browser": "~9.0.1",
"@angular/platform-browser-dynamic": "~9.0.1",
"@angular/router": "~9.0.1",
"@capacitor/android": "^1.5.0",
"@capacitor/angular": "^1.0.2",
"@capacitor/core": "latest",
"@fortawesome/angular-fontawesome": "^0.6.1",
"@fortawesome/fontawesome-svg-core": "^1.2.28",
"@fortawesome/free-brands-svg-icons": "^5.13.0",
"@fortawesome/free-regular-svg-icons": "^5.13.0",
"@fortawesome/free-solid-svg-icons": "^5.13.0",
"@gilsdav/ngx-translate-router": "^3.0.0",
"@gilsdav/ngx-translate-router-http-loader": "^1.1.0",
"@ngrx/effects": "^8.6.0",
"@ngrx/store": "^8.6.0",
"@ngrx/store-devtools": "^8.6.0",
"@ngx-translate/core": "^12.1.2",
"@ngx-translate/http-loader": "^4.0.0",
"@types/googlemaps": "^3.39.3",
"angular-cli-ghpages": "^0.6.2",
"crypto-ts": "^1.0.2",
"moment": "^2.24.0",
"ngx-cookie-service": "^3.0.3",
"ngx-image-cropper": "^3.1.6",
"ngx-toastr": "^12.0.0",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.901.0",
"@angular/cli": "^9.1.0",
"@angular/compiler-cli": "~9.0.1",
"@angular/language-service": "~9.0.1",
"@capacitor/cli": "latest",
"@types/jasmine": "~3.5.4",
"@types/jasminewd2": "~2.0.8",
"@types/node": "~13.7.1",
"codelyzer": "^5.2.1",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^5.0.1",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~2.1.1",
"karma-jasmine": "~3.1.1",
"karma-jasmine-html-reporter": "^1.5.2",
"protractor": "~5.4.3",
"ts-node": "~8.6.2",
"tslint": "^6.1.1",
"typescript": "^3.7.5"
}
}

可能会有点晚,但在Dockerfile:中

RUN npm运行构建:通用

您需要在包.json中有一个脚本,如下所示:

"build:universal": "ng build --prod && ng run jobnow:server:production"

还有这条线:

RUN npm运行测试:ssr

您可以删除它或添加其他类似的脚本:

"test:ssr": "run-p test:ssr:*"

相关内容

  • 没有找到相关文章

最新更新