Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Angular app as docker image using Node js

Trying to build angular application in docker and run as container in my local using Node js.

I have used build image using below Dockerfile, but i am not sure what i am missing while running. Can someone point me out?

Dockerfile:

FROM node:10.15.3
ENV HOME=/home
WORKDIR $HOME
RUN npm config set strict-ssl false \
    && npm config set proxy http://proxy.xxxxxx.com:8080
COPY package.json .
RUN npm install

Image created with below command successfully

docker build -t example .

I am trying to run the image using below command, but it is not helping

docker run -p 4201:4200 example
like image 927
Mohan Avatar asked May 19 '26 17:05

Mohan


2 Answers

your Dockerfile does not run/serve your application, in order to do that you have to:

  • install angular/cli
  • copy the app
  • run/serve the app
FROM node:10.15.3

RUN npm config set strict-ssl false \
    && npm config set proxy http://proxy.xxxxxx.com:8080

# get the app
WORKDIR /src
COPY . .

# install packages
RUN npm ci
RUN npm install -g @angular/cli

# start app
CMD ng serve --host 0.0.0.0

hope this helps.

like image 175
Ammar Avatar answered May 22 '26 07:05

Ammar


Container need a foreground process running, then it will not exit. If not, the container will directly exit.

For your case, you need to COPY your nodejs project to container when docker build, and also start the project in CMD like CMD [ "npm", "start" ]. As the web server not exit, then your container will not exit.

A good article here for your reference on how to dockerizing a Node.js web app.

like image 45
atline Avatar answered May 22 '26 07:05

atline



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!