How to host angular application in Docker? How to host angular application in Docker? nginx nginx

How to host angular application in Docker?


  1. Right off the bat I see a couple things, like EXPOSE

First, in your Docker config you are missing theExposeoption/line such as:

EXPOSE 4200

Insert it before your last RUN command in the docker file, to allow the port in the container (for e.g. port 4200) so the mapping from compose works (80:4200)

Its forwarding port 80 to 4200, essentially mapping your angular app.


  1. Update your config file: A good ref sample of sanitized docker config. You should compare your image with this to update your install with yarn, and copy to the correct output dir. etc.

FROM node:13.3.0 AS compile-image// installRUN npm install -g yarnWORKDIR /opt/ngCOPY .npmrc package.json yarn.lock ./RUN yarn installENV PATH="./node_modules/.bin:$PATH" # configure your expose port#expose the port   EXPOSE 4200COPY . ./RUN ng build --prodFROM nginxCOPY docker/nginx/default.conf /etc/nginx/conf.d/default.confCOPY --from=compile-image /opt/ng/dist/app-name /usr/share/nginx/html

  1. You may need to forward the port from the container to your system / host :

    docker run -p 4200:4200 test:latest