Set up a Dockerfile for your angular application with Nginx

oumaymasghayer

Oumayma JavaScript Developer

Posted on January 16, 2022

Set up a Dockerfile for your angular application with Nginx

Running your application in docker container is the first step towards production. We have to make sure that our app can build successfully , independently of our local environment.
Bellow you can find a basic dockerfile for your angular application that uses nginx server to render the html.

FROM node:12-alpine as build

WORKDIR /app

COPY package.json .

RUN yarn install

COPY . .

RUN apk add gettext

RUN yarn build --base-href

FROM nginx:latest

COPY --from=build /app/dist/hr-frontend /usr/share/nginx/html

EXPOSE 80
Enter fullscreen mode Exit fullscreen mode

The above dockerfile will run your application on port 80.
To test it, in the root of your project run:

  1. docker image build --tag <your image name> .
  2. docker run -d -p 8000:80 <your image name> This command will serve your application on port 8000. The port 80 is where your application is running inside the container.
  3. Go to localhost:8000 .
💖 💪 🙅 🚩
oumaymasghayer
Oumayma JavaScript Developer

Posted on January 16, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related