node.js - How to Dockerizing a Angular 2 web app via node js? -
i tried out finding many ways dockerizing angular 2 web app using node js not yet worked running on local not working on docker container.does have proper dockerfile , package.json file docking angular 2 app.
from node:boron # create app directory run mkdir -p /usr/src/app workdir /usr/src/app # install app dependencies copy package.json /usr/src/app/ run npm install # bundle app source copy . /usr/src/app expose 5655 cmd [ "npm","start" ]
site cant reached while accessing
below possible ways found on stack on flow not worked
docker run --rm --name my-container -it -p 8080:4200 -v $(pwd):/var/www -w "/var/www" node npm start
in package.json kept port dynamic "ng serve -host 0.0.0.0",
and suggest me server need use either nginx or node docking angular 2 web-app
"scripts": { "start": "node ./bin/www", "build": "del-cli public/js/app && webpack --config webpack.config.dev.js --progress --profile --watch", "build:prod": "del-cli public/js/app && ngc -p tsconfig.aot.json && ngc -p tsconfig.aot.json && webpack --config webpack.config.prod.js --progress --profile --bail && del-cli 'public/js/app/**/*.js' 'public/js/app/**/*.js.map' '!public/js/app/bundle.js' '!public/js/app/*.chunk.js' 'assets/app/**/*.ngfactory.ts' 'assets/app/**/*.shim.ts'" }
- first of suggest run "npm start" @ machine;
- and check if after can reach angular app in browser;
- if works - need remember @ port angular app served;
- add new run section "run npm run build:prod" right before expose line;
- set correct port @ section expose;
- run container: "docker run --rm --name my-container -it ."
- open browser @ http:127.0.0.1:here_port_from_expose_section
here small example: https://github.com/karlkori/dockerized-angular-app
also want add production better use nginx or cloudfront.
Comments
Post a Comment