0

I tried out finding many ways for Dockerizing angular 2 web app using node js but not yet worked it is running on local but not working on docker container.Does anyone have any proper Dockerfile and package.json file for docking angular 2 app.

enter image description here

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 be reached while accessing

Below are some possible ways i found on stack over flow but 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 even i kept my port as dynamic "ng serve -host 0.0.0.0",

And also suggest me which server i need to use either nginx or node for 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'"
  }

enter image description here

3
  • Your angular app must be served by any type of http servers - it can be a simple node.js file with configured "express" module inside. Can you post here the content of your package.json or at least the "scripts" section from it? Commented Apr 7, 2017 at 13:08
  • @sergiy.dragunov "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'" }, Commented Apr 7, 2017 at 13:16
  • @sergiy.dragunov i have added my script above description section Commented Apr 7, 2017 at 13:18

1 Answer 1

1
  1. first of all I would suggest to run "npm start" at your machine;
  2. and check if after this you can reach you angular app in a browser;
  3. if this works - you will need to remember at which port your angular app is served;
  4. add new RUN section "RUN npm run build:prod" right before EXPOSE line;
  5. set correct port at section EXPOSE;
  6. run you container: "docker run --rm --name my-container -it ."
  7. open browser at http:127.0.0.1:HERE_PORT_FROM_EXPOSE_SECTION

Here is a small example: https://github.com/karlkori/dockerized-angular-app

Also I want to add that for production it will be better to use Nginx or CloudFront.

Sign up to request clarification or add additional context in comments.

3 Comments

sergiy.dragunov Same error not worked with above steps
is your application private? can you share it code on github or bitbucket?
added a link to example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.